P
P
PythonLady2019-08-08 23:21:08
css
PythonLady, 2019-08-08 23:21:08

Why is css not showing up in Flask?

Perhaps the question is not difficult, but I couldn’t figure it out on my own.
This is how I have the files:
/server.py
/templates/index.html
-------------/images
----- -------/css/style.css
When I open index.html in the browser, everything is ok, everything is beautiful
I write this in server.py:

from flask import Flask, url_for, render_template

app = Flask(__name__)
@app.route('/')
@app.route('/index')
def index():
    return render_template('index.html')

if __name__ == '__main__':
    app.run(port=8080, host='127.0.0.1')

I launch, and there is html without css.
How can I make sure that the styles are connected? I hope they help me!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Yakushenko, 2019-08-08
@PythonLady

Create a static folder and put your css in it.
This is how it should look like:

/server.py
/static/style.css
/templates/index.html
-------------/images

Connection, respectively:
<link rel="stylesheet" href='/static/style.css' />

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question