0

I have a file structure like this for my website

css
  style.css
  other files...
templates
  index.html
  other files...

and I am trying to refer to style.css from my index.html file.

I've tried to go back a directory with ../

<link rel="stylesheet" type="text/css" href="../css/style.css">

but it's giving me a 404 error. I have tried to refer to other files in different directories using the same method, but that doesn't work either. Any ideas?

P.S. Not sure this matters, but this is a Python application using the Flask framework and PostgreSQL

1 Answers1

1

The fact that it's a Flask application actually matters quite a bit. If this were something like vanilla PHP, your html page would be served up at yoursite.com/templates/index.html. Because it's Flask, you're probably serving it at yoursite.com/index (or whatever other path you've decided).

Your relative reference to the css path is actually trying to go a level above the root domain. If you changed the reference to the below and set up a path to serve that file at that route, it would work:

<link rel="stylesheet" type="text/css" href="/css/style.css">

But that would be a lot of effort. Instead, you should be using Flask's built in url_for() and /static folder structure (instead of /css)

<link rel=stylesheet type=text/css href="{{ url_for('static', filename='style.css') }}">
gtdavidv
  • 276
  • 3
  • 6