-1

I have a simple flask app:

from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
    return render_template('basic.html')

if __name__ == '__main__':
    app.run(debug=True)

Directory structure(as recommended):---

\templates
    \basic.html
\static
    \basic.css
basic.py

And I have connected my CSS file in the HTML using:---

<link rel="stylesheet" href="{{ url_for('static', filename='basic.css') }}">

The problem: The changes I'm making to my CSS file aren't taking place in my app/website even after reloading the browser and when I checked the sources in developer tool it turns out that the styling isn't applied! This is my CSS file:--

h2{
  font-size: 50px;
  color: red;
  background-color: green;
}
p{
  color: blue;
}
h3{
  font-size: 100px;
  color: green;
  background-color: red;
}
h4{
  color: purple;
  background-color: blue;
}

And this is what is shown in the developer tools:--

h1{
  font-size: 50px;
  color: red;
  background: green;
}
p{
  color: blue;
}

Just that!! Here it is:

I looked at other answers too (Here) but I'm unable to understand what exactly am I doing wrong!

Edit: I'm not seeing the changes after navigating to the file in the browser too:--

Here:

Edit 2: Okay! The hard refresh way(Ctrl + shift + R) is working but I have to do it every time I make any change! Isn't there any other way?

Kashi
  • 99
  • 2
  • 11
  • How are you calling this in your HTML? – Abhishek Rai Oct 29 '20 at 11:43
  • There can be multiple reasons for this, you can try to debug it as, check in html what's your css static file path, then navigate over there and see what's inside, in your case it's `http://127.0.0.1:5000/static/basic.css`, if you seeing old changes, then maybe you have to hard refresh (like Ctrl + Shift + R) or try incognito browser or restart your flask server – Shashank Oct 29 '20 at 11:45
  • i have also experienced the same issue and it is because of browser caching. Just hard reload and it will update successfully ( i agree with @Shashank) – Nalin Angrish Oct 29 '20 at 11:52
  • @Anrar Ahmed. I have mentioned it: I linked them using `` `` – Kashi Oct 29 '20 at 12:01
  • @Shashank I'm not seeing the changes even after navigating to that css file in the browser! – Kashi Oct 29 '20 at 12:29

1 Answers1

0

as you know this is one the most problem from a flask framework. I didn't find any technical stack for solving this. but you can clear all of your browser cookies or clear the localhost histories as a running on your local host. in addition if you changing your browser it will be working done.

onehamed
  • 127
  • 9