H
H
Hlib2019-05-27 16:38:06
css
Hlib, 2019-05-27 16:38:06

Flask does not see the css file connected to the html template, what should I do?

ANSWER:
There was no information about this all over the Internet, which is rather strange, or I just don’t know how to google
Add the line
static_path = os.path.join(project_root, '../client/static') to the flask
And rewrite app as
app = Flask(__name__, template_folder=template_path, static_folder=static_path)
Everything worked .
When trying to include a css file with html using Flask, it just isn't found.
404
I connect for a reason
+
Mb the fact is that in order to connect html to Flask I also wrote
import os
import sys
project_root = os.path.dirname(__file__)
template_path = os.path.join(project_root, '.. /client')
app = Flask(__name__, template_folder=template_path)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
arhansolo, 2019-12-17
@arhansolo

This is due to the fact that style files are cached in your browser.
You can clear the cache with CTRL+F5.
But users of your application will not reset the cache every time they visit your site.
It is possible to disable caching altogether. But a better approach is to specify the version of your styles each time you change them. So the browser itself will update the cache when it sees that the user has an old version. v=1, v=2 and so on.

<link rel="stylesheet" type="text/css" href="{{ url_for( 'static', filename='style.css', v=1)}}">

P
Pavel Shvedov, 2019-05-27
@mmmaaak

flask.pocoo.org/docs/1.0/tutorial/static

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question