0

Here is my reduced html code:

{% load staticfiles %}
<html lang="en">
    <head> 
        <link href="{% static '/css/buttonform.css' %}" rel="stylesheet">
    </head>
</html>

And here is my settings.py:

INSTALLED_APPS = ['django.contrib.staticfiles',]
STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_in_env", "static_root")

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static_in_pro", "our_static"),
)

The css file exists in the STATICFILES_DIRS but the error comes as: Not Found: /css/buttonform.css

4
  • 2
    How about without the leading slash? {% static 'css/buttonform.css' %} Commented Jul 2, 2016 at 14:06
  • @alecxe It worked! But the again, in the Django Tutorial the bootstrap css part is having a leading / slash before the path, why is that so? Commented Jul 2, 2016 at 14:11
  • Hm, when the presenter shows the templates, I see the static path not starting with slash - for example here. Commented Jul 2, 2016 at 14:14
  • @alecxe Yes I just realized! It was a syntax error and the same error was shown. Thank you again :) Commented Jul 2, 2016 at 14:16

1 Answer 1

3

Change

<link href="{% static '/css/buttonform.css' %}" rel="stylesheet">

to

<link href="{% static 'css/buttonform.css' %}" rel="stylesheet">
Sign up to request clarification or add additional context in comments.

1 Comment

the extra slash at the beginning of the path means "root directory", so it would try to find it starting at your app directory, without it, it would look for the file starting at the static folder. The issue here is your stylesheet never gets loaded into your html because it can't find it in the first place.

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.