Hey the error I am getting is:
“GET /static/polls/style.css HTTP/1.1” 404 179"
I have a css file located at: mysite/polls/static/polls/style.css
and an index.html: mysite/polls/templates/polls/index.html
I have added this at the top of my index.html as instructed in the tutorial:
{% load static %}
<link rel=“stylesheet” type=“text/css” href=“{% static ‘polls/style.css’ %}”>
My settings.py contains:
# STATIC_URL = ‘static/’
STATIC_URL = ‘/static/’
I have tried both versions and still get the same error.
I have restarted the server and I have done a hard refresh on the browser.
I have also tried this solution I found on Stack over Flow, but it did not work:
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'polls/static')]
I am not sure what I am doing wrong
Hey there!
One thing to keep in mind is that Django is actually finding your static file at polls/style.css
, it’s not serving it apparently. I say it because if you try to use the {% static some_app/does_not_exist.css %}
you’ll get an error while loading the template, and that does not seem to be the case.
I would recommend that you check if your DEBUG
setting is defined to True
, Django will only serve static files when this configuration is set to True
.
Another thing is to make sure that you’ve setup the INSTALLED_APPS
settings correctly as defined on the part 2 of the tutorial.
Hey,
My debug is not set to true.
I have set it to false.
If it is set to false how do we view static files in that scenario ?
Thanks for you input
That’s another topic, this is covered on the deployment section of the documentation.
But when you’re developing your application you should always have DEBUG=True
otherwise you won’t be seeing your static files and all of the goodies that comes when the DEBUG mode is set.
1 Like