Django static files

2 views
Skip to first unread message

eculver

unread,
May 12, 2009, 2:27:01 AM5/12/09
to Django users
I know this one has been covered pretty well, and I'm not a "total"
newb to django, but something alludes me here. Why when I put:

if settings.DEBUG:
urlpatterns += patterns('',
(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT},
)

in my urls.py does it fail and output:

Page not found: /var/lib/python-support/python2.6/django/contrib/admin/
media/css/master.css

Why is it even looking in /var/lib/python-support/python2.6/django/
contrib/admin/ if I've configured MEDIA_ROOT in my settings.py to an
absolute path to my project's media source... just seems strange? Any
ideas would be greatly appreciated.

Tim Chase

unread,
May 12, 2009, 6:53:53 AM5/12/09
to django...@googlegroups.com


Had the same problem on a project I was just working on. I think
I had to change the settings.ADMIN_MEDIA_PREFIX to some other
location because it was superseding my settings.MEDIA_ROOT

-tim


eculver

unread,
May 13, 2009, 12:04:34 AM5/13/09
to Django users
I figured this out. Your advice lead me in the right direction, but I
went ahead and configured my urls.py like this:

# For serving static media files (css, js, images)
if settings.DEBUG:
urlpatterns += patterns('',
(r'^content/(.*)$', 'django.views.static.serve',
{'document_root': os.path.join(settings.PROJECT_PATH, 'content')}),
)

And set my PROJECT_PATH accordingly in settings.py (/home/me/
project_name). I'm thinking that the (r'^media/(.*)$... url pattern
conflicts with django admin URLs and based on the order of inclusion,
overrides what I had as my pattern for serving static files in my
development environment. Either way, it works now. Thanks Tim!

On May 12, 3:53 am, Tim Chase <django.us...@tim.thechases.com> wrote:
> eculver wrote:
> > I know this one has been covered pretty well, and I'm not a "total"
> > newb todjango, but something alludes me here. Why when I put:
Reply all
Reply to author
Forward
0 new messages