58

I am using Flask (the python Package) on my mac, when I first wrote my css it displayed ok. However when I updated it and tried to check it, I only see the first css styles. I have tried restarting the terminal, as well as reinstalling Flask. Any suggestions? Thanks. Heres the HTML:

 <!DOCTYPE html> <html> <head> <title>Title</title> <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}"> </head> <body> <header> <div class="header"></div> <div class="logo"> <center><img src="/static/img/p_logo.png" alt="pic"/></center> </div> </header> <div class="container"> {% block content %} {% endblock %} </div> </body> 

And heres the CSS:

 * { font-family: "Times New Roman", Times, serif; } header { background-color: #000000; width: 100%; height: 7px; } 
10
  • Can you include the relevant code? Commented Feb 11, 2014 at 22:53
  • ok, I updated it with css and html. Any other suggestions> Commented Feb 11, 2014 at 23:52
  • 66
    Did you try reloading the page using Shift + Ctrl + R? (This clears the browser's cache for the page.) Commented Feb 12, 2014 at 1:08
  • 5
    CMD (or CTRL on Windows) + SHIFT + R = success! Thank you. Commented Feb 12, 2014 at 1:19
  • 2
    I am also facing it..........This is a problem with the flask server...this should be addressed by the flask Team!!! Commented Sep 18, 2016 at 11:30

1 Answer 1

54

Problem is, as already said, related to browser cache.

To solve that, you could add some dynamic variable to your static (css, js) links. I prefer last modified timestamp for each file.

/static/css/style.css?q=1280549780 

Here is a snippet for that:

http://flask.pocoo.org/snippets/40/

@app.context_processor def override_url_for(): return dict(url_for=dated_url_for) def dated_url_for(endpoint, **values): if endpoint == 'static': filename = values.get('filename', None) if filename: file_path = os.path.join(app.root_path, endpoint, filename) values['q'] = int(os.stat(file_path).st_mtime) return url_for(endpoint, **values) 
Sign up to request clarification or add additional context in comments.

12 Comments

This is totally problematic to work with flask...is there any other solution??
It's not a problem inherent to Flask framework but browser caching. You could always disable browser cache by appropriate headers, but this is not a solution for production server. There are only two hard things in Computer Science: cache invalidation and naming things. -- Phil Karlton
Ive never had this problem with anything apart from flask
Jacek Kaniuk: Are you sure it's related to browser cache? When I install brand new browser, I have still the same problem. Yes, the first time I open the url, the .css files loaded are not the newest ones.
@culter Yes, it's related to browser cache. There are similarities to how the browsers cache css and js, so you'll find this problem appears in all browsers.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.