Reputation: 11
from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
return "Index!"
@app.route("/hello")
def hello():
return "Hello World!"
@app.route("/members")
def members():
return "Members"
if __name__ == "__main__":
app.run(debug=True)
I am trying to run the above example program, I am not sure how to check the output in browser. I tried the links - http://127.0.0.1:5000/hello , http://127.0.0.1:5000/members nothing come up. Help me if I am missing anything ?
Upvotes: 0
Views: 15559
Reputation: 2354
If you are new to Flask follow these steps and you will be able to view the paths on a browser. First install virtualenv & pip.
sudo apt-get install python-virtualenv
sudo apt-get install python-pip
Create a directory wher you will store your object.
mkdir yourflaskapp
cd yourflaskapp
Create your virtual environment where you will install flask.
virtualenv yourvirtualenv
After succesfully creating your virtual environment, activate it using the following command. To deactivate type and run deactivate
.
source yourvirtualenv/bin/activate
Now install flask in your virtual environment.
pip install flask
Create file app.py below then run python app.py
.
from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
return "Index!"
@app.route("/hello")
def hello():
return "Hello World!"
@app.route("/members")
def members():
return "Members"
if __name__ == "__main__":
app.run(debug=True)
Upvotes: 0
Reputation: 14362
Make sure Flask is installed in your system you can try something like $ pip freeze | grep flask
, if not run
$ pip install Flask
And when you run your app like $ python <filename>.py
you see something like
* Running on http://localhost:5000/
Upvotes: 1