Python Flask Basics Welcome to Flask Clean URL Arguments

Ibrahim Khan
Ibrahim Khan
3,353 Points

Have to relaunch the program after changing code.

from flask import Flask

app = Flask(__name__)


@app.route('/')
@app.route('/<name>')
def index(name="Treehouse"):
    return "Hello from {}".format(name)

@app.route('/add/<int:num1>/<int:num2>')
def add(num1, num2):
    return '{} + {} = {}'.format(num1, num2, num1+num2)

app.run(debug=True, port=8000, host='0.0.0.0')

Using the code above. debug is set to True. I'm finding that in addition to saving the program, I have to relaunch it in the console, otherwise the port8000 view redirects me to the same webpage as the one coming from older version. Pls tell me what I may be doing wrong. Thanks.

2 Answers

Try this in the terminal:

$ export FLASK_ENV=development
$ flask run

http://flask.pocoo.org/docs/1.0/quickstart/#debug-mode

Ibrahim Khan
Ibrahim Khan
3,353 Points

Thank you for the info,

so, I'm able to pass export FLASK_ENV=development but I get an error on the next bit, which is flask run:

bash: flask: command not found.

Now i'm not sure if this has something to do with the fact that this is being run on workspaces on treehouse servers.