11

Here is my project hierarchy:

Project

enter image description here

Here is my HTML file :

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Hello World</title> <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='custom.css') }}"/> </head> <body> <h1>Hello World</h1> </body> </html> 

My .py flask file :

from flask import Flask, render_template, redirect, json, url_for, request, abort from pymongo import MongoClient client = MongoClient() db = client.web_zoo app = Flask(__name__) @app.route('/') def index(): return render_template('home.html') if __name__ == "__main__": app.run(debug=True) 

And my CSS file :

body { color: green; } h1 { color: orange; } 

The HTML and .py files work fine and the HTML is rendered and displayed on the page. However the CSS doesn't change. It just displays it in normal black text.

NOTE : All those imports are there as I was doing something else. I stripped off everything else and still have this problem.

I can link bootstrap to it, and the CSS works, but not for my own CSS files.

I have looked at and tried these following solutions :

CSS Problems with Flask Web App

Application not picking up .css file (flask/python)

best way to override bootstrap css

It's probably quite obvious but I'm stuck. Any help? Thanks in advance!

EDIT - I have added a picture of the project hierarchy now instead of just a list. As you can see there are some other HTML files in there too, but none are used nor referenced.

11
  • Are you sure that tag <link> gets a correct path to your css file? Commented Aug 8, 2017 at 12:08
  • 4
    Have you tried to go to url where your css files and hit F5? e.g. go to 127.0.0.1:8000/static/custom.css (with your browser) and hit F5. For me that did the job. Commented Aug 8, 2017 at 12:14
  • 1
    @A.Lord I don't remeber actually (it was a while ago when i had this issue), but here's an interesting thread: stackoverflow.com/questions/21714653/flask-css-not-updating. Commented Aug 8, 2017 at 12:18
  • 1
    @A.Lord stackoverflow.com/questions/2263096/… Also this seems to be related to this issue Commented Aug 8, 2017 at 12:27
  • 1
    Google Chrome stores styles in its own cache. If you make changes to the CSS and try to access the same webpage, the last saved CSS is retained. You have to go directly to the CSS File (accessed over HTTP) and refresh for the changes to be reflected Commented Aug 8, 2017 at 13:25

1 Answer 1

45

Try

CTRL+SHIFT+R

in Chrome to reload the CSS.

On Mac try:

CMD+SHIFT+R

Otherwise right-click on the page in Chrome, select Inspect and select the Console tab to see what errors you get.

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome thank you! Much easier than having to refresh the CSS file each time.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.