Answer the question
In order to leave comments, you need to log in
Why is css and js not connected?
I am writing a website using flask_socketio. But for some reason, css and js are not connected, although everything is correct. When I run just html, everything is loaded. To render the template I use the following:
@app.route('/')
def index():
return render_template('index.html', async_mode=socketio.async_mode)
Answer the question
In order to leave comments, you need to log in
The static must be in the static directory when served by Flask:
├───static
│ ├───css
│ │ style.css
│ │
│ └───js
│ script.js
│
├───templates
│ hello.html
│
│ app.py
<script src="{{ url_for('static', filename='js/script.js') }}"></script>
you need to distribute the static somehow. Use nginx or something else for this. In the meantime, you can manually create handlers for directories by type
from flask import Flask
# set the project root directory as the static folder, you can set others.
app = Flask(__name__, static_url_path='path/to/staic/')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question