Basically I have followed step by step this guide https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uswgi-and-nginx-on-ubuntu-18-04 , and right now I can see my website www.XXX.com perfectly with the text "Hello There".
The first issue is that no matter how much I change the file that "return", I will always see the text "Hello There". I tried also restarting nginx many times, but it doesn't work.
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
#line that I usually try to edit, but nothing happens...
return "<h1 style='color:blue'>Hello There!</h1>"
if __name__ == "__main__":
app.run(host='0.0.0.0')
Furthermore the tutorial doesn't explain where to have the folders "static" and "template" in order to have them communicating by Flask. I have read so much about changing nginx conf file and/or redirecting, it is almost a week I am trying every tutorial I see, but nothing works so far.
How can I make the html changing? Where should I write an index.html so that Flask can actually see it and "index.html" can do POST request to it? In localhost everything looks different, since there is templates folder. But here it doesn't seem to care.
Thanks!
uWSGI does not reload the python code by default. You have to either manually restart or reload uWSGI when you change code, or configure uWSGI to auto reload. uWSGI has many configuration options that you can use.
For development you can use the --python-autoreload
option. This will reload every time code changes, similar to django runserver. There's a performance cost for this option, so it should not be used in production. Options can be command line flags or included in the uwsgi config file.
[uwsgi]
module = wsgi:app
python-autoreload = true
...
In production there are many other ways to reload the app. The simplest might be to just send a SIGHUP
signal to the uwsgi process. For example using the linux command pkill
pkill --signal SIGHUP uwsgi
Another option is to use touch-reload
. That will only watch a single file for changes and reload uWSGI if the file is modified. So this can be used in production without much overhead.
[uwsgi]
module = wsgi:app
touch-reload = /tmp/somefile
...
Use the command touch /tmp/somefile
to update the file timestamp.
Several other ways to configure reloading are described in this section of the uWSGI docs: The Art of Graceful Reloading
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.