2

I am facing difficulty in accessing CSS and bootstrap files inside HTML within localhost:5000 in flask programming.

I've already tried including the CSS files within static folder but it doesn't work.

<head>
<title>HOME PAGE</title>
    <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='bootstrap.css') }}">

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

I expect all the CSS modules to be included in the HTML file without any obstacles.

8
  • add your HTML code & folder structure Commented Mar 26, 2019 at 5:00
  • did you try placing bootstrap.css first and then homestyle.css ? Commented Mar 26, 2019 at 5:12
  • Have you checked that the path to your css files is correct? it would not static/css/homestyle.css instead? Commented Mar 26, 2019 at 7:06
  • @VillageMonkey yea but it doesn't work Commented Mar 30, 2019 at 4:03
  • @LaljiTadhani the folder structure is templates and a static as sub folder within templates Commented Mar 30, 2019 at 4:36

1 Answer 1

1

Try this:

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

Edit: Make sure your folder structure matches the following:

static/
├── homestyle.css
├── bootstrap.css
templates/
├── index.html
app.py

The static folder should be at the root, not inside the templates folder.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.