Categories
Python Answers

How to fix Python Flask app not picking up .css file?

Spread the love

Sometimes, we want to fix Python Flask app not picking up .css file.

In this article, we’ll look at how to fix Python Flask app not picking up .css file.

How to fix Python Flask app not picking up .css file?

To fix Python Flask app not picking up .css file, we should set up the static file folder for our Flask app.

We put the CSS file in the /static/styles folder in our Flask project folder.

Then we add the link tag for the CSS file by writing

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

We set the href attribute to {{ url_for('static',filename='styles/mainpage.css') }}.

to reference the mainpage.css file with the link tag.

Conclusion

To fix Python Flask app not picking up .css file, we should set up the static file folder for our Flask app.

We put the CSS file in the /static/styles folder in our Flask project folder.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *