CSS Link Static Page

2.5k views Asked by At

Before you mark this as a duplicate, I have indeed already looked at the django forums, tutorials, etc.

I have a blog I made with Django, the blog's index page template needs to have a css stylesheet that I have linked in my static folder. (Folder Tree attached attached).

In the html for the template I have the following code:

{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'blog/style.css' %}" />

Why is this not working! Thanks!

EDIT: I found this in my sitename/base.py file:

STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]

STATICFILES_DIRS = [
    os.path.join(PROJECT_DIR, 'static'),
]

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

Could it be a problem with the directories? manage.py collectstatic -l says:

196 static files symlinked to '/home/myusername/webapps/mysite/static'.

2

There are 2 answers

1
Mauricio Cortazar On

comment the STATICFILES_URL [..], STATICFILE_FINDERS [..] and add the staticfiles_url like this:

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)
3
athultuttu On

Check the console while opening the view accessing this CSS file. The cmd console will print the absolute URL they will use to find CSS file. From the url, you can identify what is the problem. See how the URL is built.