Issue
I have started to work on flask, and the problem is i have created a css file in static folder and wanted to load that css file on template.
but it is not loading css file even if i try this on incognito mode i thought it could be a cache problem but it does not.
<!DOCTYPE html>
<title> Welcome to My Blog</title>
<link rel="stylesheet" type="=text/css" href="{{ url_for('static', filename='style.css?v=0.01') }}">
<h2>Hey there {{ name }}</h2>
Blog.py
from flask import Flask, request, render_template
app = Flask(__name__)
...
@app.route('/profile/<username>')
def profile(username):
return render_template("profile.html", name=username)
...
if __name__ == '__main__':
app.run(debug=True, port=8080)
style.css
h2{
color: #00bfff;
}
Solution
The problem is that you include the query string in your filename.
url_for('static', filename='style.css?v=0.01')
The url path results in static/style.css%3Fv%3D0.01
, because the special characters get encoded. To fix this you must add query elements as keyword arguments:
url_for('static', filename='style.css', v=0.01)
Additionally:
- Your file is called
stye.css
and notstyle.css
- Your
<link>
tag saystype="=text/css"
and nottype="text/css"
as it should
Answered By - vallentin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.