tutorial p.6 problem: style.css isn't loaded

831 views
Skip to first unread message

Janek Warchoł

unread,
Feb 5, 2014, 12:45:20 PM2/5/14
to django...@googlegroups.com
Hello,

i'm following Django's tutorial (very nice, btw) and static files don't work for me.  I have a test project created along the previous parts of the tutorial, and now i'm here: https://docs.djangoproject.com/en/1.6/intro/tutorial06/#customize-your-app-s-look-and-feel

According to instructions, I've added a style.css file to BASE_DIR/polls/static/polls/ subdir and inserted

{% load staticfiles %}

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

into my polls/templates/polls/index.html - however, it doesn't have any effect (i.e. the links in the poll list aren't green), and when i look into the shell where Django development server is running, i see

"GET /static/polls/style.css HTTP/1.1" 404 1649

so, it seems that the file cannot be accessed at all.  But i'm at a loss of why it doesn't work :(

Any ideas?
If anyone wants to look at my code, it's here:
https://github.com/j-warchol/django-test

best,
Janek

Daniel Sears

unread,
Feb 5, 2014, 10:48:42 PM2/5/14
to django...@googlegroups.com
templates/admin isn't necessary. Instead you should extend both TEMPLATE_DIRS and STATICFILES_DIRS to include the templates and static files for the admin package:

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, 'templates'),
    '/opt/python-venv/lib/python2.7/site-packages/django/contrib/admin/templates/',
)
STATICFILES_DIRS = (
    '/opt/python-venv/lib/python2.7/site-packages/django/contrib/admin/static/',
)



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABmDZEObsanqcDVBC9-R%3DiVen4eocRFcFc16oXHwkQY5PUPr7A%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Janek Warchoł

unread,
Feb 6, 2014, 7:52:31 AM2/6/14
to django...@googlegroups.com
Hi,


W dniu czwartek, 6 lutego 2014 04:48:42 UTC+1 użytkownik Daniel Sears napisał:
templates/admin isn't necessary. Instead you should extend both TEMPLATE_DIRS and STATICFILES_DIRS to include the templates and static files for the admin package

Well, templates/admin/base_site.html was actually a modified version of the original template.  Admittedly, index.html is redundant.

As for the css problem, everything works today and i have no idea why it didn't yesterday - i haven't changed anything.

best,
Janek

bowei xu

unread,
Dec 27, 2017, 7:54:51 AM12/27/17
to Django users
Same error happens to me, 

Restart mysite with `python manage.py runserver` fix it.

It may because new created files not auto detected by django.

Best,

Jason

unread,
Dec 27, 2017, 11:50:10 AM12/27/17
to Django users
Correct.  Django's dev server has file watchers looking at the files currently in the project when its started, but creating new files doesn't add them to said file watchers.  Only solution is to restart the dev server process.
Reply all
Reply to author
Forward
0 new messages