0

Here is the link in my html file (json_form.html)

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

I am trying to link json_form.css to json_form.html, I have already tried to use an absolute file path but to no avail.

I get this error whenever json_form.html loads on my web app:

"GET /assets/json_form.css HTTP/1.1" 404 -

so I guess it's unable to find the CSS file for some reason. I've seen a lot of people with similar problems but their answers don't help me. Can someone run me through everything that could be wrong with this?

Here is my file directory for reference:

enter image description here

1 Answers1

1

You need to configure Flask with the name of your static directory.

When you initialize your Flask app, you can set:

app = Flask(__name__, static_url_path='/assets')

NOTE: By default, it's /static, so if you rename your assets folder to static, that should work as well.

and then in your HTML, you can use the asset:

<link rel="stylesheet" type="text/css" href="json_form.css">
frozen
  • 2,114
  • 14
  • 33
  • when I set the static url path to that I get an error telling me that urls must start with a leading slash – LarryYourWaiter Jun 11 '21 at 18:14
  • edited, setting it to `/assets` might work. @LarryYourWaiter – frozen Jun 11 '21 at 18:16
  • already tried that, and nothing. Plus the problem probably isn't that I have the wrong path since it autofills to json_form.css when im typing it in with the file icon and everything, so it knows what file im referencing. – LarryYourWaiter Jun 11 '21 at 18:18