Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask css not updating [closed]

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;  }        
like image 278
ng150716 Avatar asked Feb 11 '14 22:02

ng150716


1 Answers

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) 
like image 101
Jacek Kaniuk Avatar answered Sep 24 '22 03:09

Jacek Kaniuk