Posts

Showing posts with the label Flask

How to run a Python program over the internet?

Image
What am I trying to solve? I want to run a python program whenever I need and get some information out of it. The problem is, I want to call that through internet. And I want to show the content on a web page or some UI container. That's it. Let put this as a requirement.Problem: Display some information on my web page calculated by a python program. 
How do we do it on our local computer? We run our program as : python my_program.py .So may be I can do something like: www.mywebsite.com/my_program.py . Can we? No idea.

I expect to collect the response in some variable (no idea how can I create a variable in the first place on html) and then display the contents of this variable . Displaying a simple text on html is known , so that should be easy.


The program You must remember that we want some information from our program . It's a basic GET call where you just ask for some information from a server. You may or may not pass some inputs while doing this.

fromflaskimportFlaskfromflas…

Test server that accepts GET/POST calls using Python Flask

I was trying out Flask. In the process, I made a website that behaves like a server. It can help you test GET and POST calls.

It goes like this .


fromflaskimport Flask, request app = Flask(__name__) @app.route('/method', methods=['GET', 'POST']) @app.route('/method/<wish>', methods=['GET', 'POST']) defmethod_used(wish=None): if request.method =='GET': if wish: if wish indir(request): ans =None s ="ans = str(request.%s)"% wish exec s return ans else: return'This wish is not available. The following are the available wishes: %s'% [method for method indir(request) if'_'notin method] else: return'This is just a GET method'else: return"You are using POST"
When I run this, this…