Reputation:
My settings.py
contains the following configuration parameters.
STATIC_ROOT = ''
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
'C:/Users/ABC/Desktop/DBMS/DjangoProject/tvshows',
)
My project's CSS file is located at C:/Users/ABC/Desktop/DBMS/DjangoProject/tvshows/static/default.css
.
I have a mock HTML file that should pull in the CSS content, but the URL is a 404.
<link rel="stylesheet" href="{{ STATIC_URL }}static/default.css" />
What am I doing wrong?
Upvotes: 1
Views: 4085
Reputation: 39287
Things to check:
DEBUG = True
in settings.py
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
# ... the rest of your URLconf goes here ...
urlpatterns += staticfiles_urlpatterns()
use context processor
or load static
if {{ STATIC_URL }}
isn't working
If {{ STATIC_URL }} isn't working in your template, you're probably not using RequestContext when rendering the template.
As a brief refresher, context processors add variables into the contexts of every template. However, context processors require that you use RequestContext when rendering templates. This happens automatically if you're using a generic view, but in views written by hand you'll need to explicitally use RequestContext To see how that works, and to read more details, check out Subclassing Context: RequestContext.
Upvotes: 4
Reputation: 6359
<link rel="stylesheet" href="{{ STATIC_URL }}default.css" />
You need to also edit your urls:
Upvotes: 3