Issue
According to the Flask documentation,
The flask script is nice to start a local development server, but you would have to restart it manually after each change to your code. That is not very nice and Flask can do better. If you enable debug support the server will reload itself on code changes, and it will also provide you with a helpful debugger if things go wrong.
To enable all development features (including debug mode) you can export the FLASK_ENV environment variable and set it to development before running the server:
$ export FLASK_ENV=development
$ flask run
However, in my very simple example, code changes still don't take effect until I restart the server. I've set up the particular script I want to run with export FLASK_APP=hello.py
and the script is as follows:
from flask import Flask, url_for, request, render_template
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!!"
While the Flask development server is running, I change the return value by adding or removing an exclamation mark and saving the file. Then I refresh the page on http://127.0.0.1:5000/
in Chrome, but the number of exclamation points is unchanged. Once I quit Flask in the terminal using Ctrl-C
and restart it and then refresh the page again, I get the proper number of exclamation points.
This is on a Mac, Python 3.6.0 (Anaconda), Flask 0.12.
Am I misunderstanding how the development server can help me, or is there anything else you think I should check? I'm quite new to Flask.
Solution
Try
FLASK_APP=app.py FLASK_DEBUG=1 TEMPLATES_AUTO_RELOAD=1 flask run
FLASK_DEBUG
will get you the behavior you're looking for now; TEMPLATE_AUTO_RELOAD
will get you the behavior you'll need as soon as you starting using templates.
Answered By - Dave W. Smith
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.