how to reload the flask server when I change my css code?

Viewed 3920

I am trying to edit my CSS code in the static folder. But the problem is: Flask is not reloading CSS changes.

<head>
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='style.css') }}">
</head>

I expected the changes but there is no change on editing the css file.

4 Answers

I had the same problem and it was the browser cache not clearing out. I found a solution for Chrome and Firefox: hold down the Shift key while clicking the reload button

My guess is that static files are not checked for changes, even when Flask runs in debug mode. Additionally, CSS files are rather more browser related than to the application itself.

Regards, Thomas

You can use:

  • FLASK_RUN_EXTRA_FILES environment variable
  • --extra-files commandline arg
  • extra_files array arg to app.run()

see extra files docs

You need to set reload template to true

app = Flask(__name__)
app.config["TEMPLATES_AUTO_RELOAD"] = True
Related