I am a beginner in web programming using Flask in Python. I've built a web page the takes a couple of inputs from the user and clicking a command button on the page leads to another Python module's main method being invoked. I want to print the console outputs of that python script to a webpage(continuously if possible). Sample code is:
> @app.route('/register', methods=["POST"])
> def register():
> ip_address = request.form.get("IP_ADDRESS")
> router_location = request.form.get("Routers_Location")
>
> def g():
> output = xyz.main(ip_address, router_location)
> for line in output:
> yield line
>
> return Response(g(), mimetype='text/html')
Where xyz is the python script that I am importing in the above code and main() contains few print statements. Currently, I am using a list to have the content of the print statements appended to it and return it back to the caller function(In this case, the caller is g()).
I need to print all the print statements to a web page as it prints on the console. Any help would be appreciated.
Aucun commentaire:
Enregistrer un commentaire