2

I have a Flask app that sets a custom root_path.

app = Flask( __name__, root_path='flask_news' ) @app.route('/login') def login(): return render_template('login.html') 

Flask can serve flask_news/templates/login.html but will not find the required CSS, which is under flask_news/static/bulma.css

In my template file I'm asking for the CSS like so:

<link rel="stylesheet" href="{{url_for('static', filename='bulma.css')}}"> 

and the head of the served webpage looks like

<link rel="stylesheet" href="{{url_for('static', filename='bulma.css')}}"> 

Why is Flask not able to serve the required CSS? I think I need to change something in how the static folder is located but I'm not sure on how.

2 Answers 2

6

Perhaps you can try specifying the static directory as well as the templates directory locations when initializing your application, something along the lines of:

app = Flask(__name__, static_folder='./flask_news/static', template_folder='./flask_news/templates') 

Hopefully that helps!

Sign up to request clarification or add additional context in comments.

1 Comment

This helped, setting both the template folder and the static folder did the thing.
1

You can define the static folder to be whatever you'd like, as in this case you can set it up to './flask_news/static/'

To do so, when you initialize your Flask object, pass in the path to the static_folder parameter:

app = Flask(__name__, static_folder='./flask_news/static') 

1 Comment

Unfortunately that still doesn't do it. And I have checked that the static folder is present in that location. Is there a way to debug this? or keep setting the static folder untill it hits?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.