P
P
Potato-and-Cucmber2020-09-05 21:25:03
Flask
Potato-and-Cucmber, 2020-09-05 21:25:03

How to auto "update" templates?

There is a code that outputs index.html:

from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def main():
    return render_template("index.html")

if __name__ == '__main__':
    app.run()


When the server is running, any changes to index.html will not output the modified file.
I couldn't find it on Google, but I've been looking for a long time.
How to make auto "update"?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2020-09-05
@Potato-and-Cucmber

This can only be done in debug mode, for this you need to pass the debug=True parameter to the run method . In production, this greatly reduces performance. It's better to configure the WSGI server to restart under certain conditions, and create those conditions on changes.

P
pcdesign, 2020-09-06
@pcdesign

Through a parameter in the config:
app.config["TEMPLATES_AUTO_RELOAD"] = True
https://flask.palletsprojects.com/en/1.1.x/config/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question