Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.