4

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
  • 1
    Is it possible that your CSS is being cached by your browser? Commented Jun 26, 2019 at 6:31
  • yes , if i manually reload the server the output is being changed ! Commented Jun 26, 2019 at 6:35
  • 1
    Try Hard Refresh - Ctrl + F5 or hold Ctrl and click on the Refresh button on your web browser. Commented Jun 26, 2019 at 7:36
  • Apart from control = F5, flask offers an option to add extra files to be monitored and cause restart in debug mode stackoverflow.com/questions/43688777/…. I have not tested this on css files, but it might be worth a try
    – gittert
    Commented Jun 26, 2019 at 11:18

4 Answers 4

14

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

1

You can use:

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

see extra files docs

0

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

0

You need to set reload template to true

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.