Oleg Oltar wrote: > Hi! > > I am trying to setup django to use static files for development purposes. > I used http://docs.djangoproject.com/en/dev/howto/static-files/ > > But actually failed to serve anything :( > > My urls.py > > urlpatterns = patterns('django.views.generic.simple', > > (r'','direct_to_template',{'template':'index.html'}), > ) > if settings.DEBUG: > urlpatterns += patterns('', > (r'^media/(?P<path>.*)$','django.views.static.serve', {'\ > document_root': '/Users/oleg/media/spilka/'}), > ) > > But needed media is not loaded, e.g. > > `-- spilka > |-- css > | `-- styles.css > > And http://127.0.0.1:8000/media/css/styles.css > gives Page not found: > /usr/local/lib/python2.5/site-packages/django/contrib/admin/media/css/styles.css You've run into a "gotcha" with your MEDIA_URL and ADMIN_MEDIA_PREFIX. Basically the development server will add the static file view automatically based on the ADMIN_MEDIA_PREFIX url. This is set to '/media' so your own media URL is passed, and it is trying to serve the files from the admin media.
One way to fix this is to change your url from /media to something else, and leave all the admin media at /media. Usually what I do is change the ADMIN_MEDIA to something else. '/admin/media' makes sense to me, so that's usually what I set it to. Some people set their MEDIA_URL url to something like '/static'. Another logical way to set the URLs is to have MEDIA_URL be '/media' and ADMIN_MEDIA_PREFIX set to '/media/admin' Hopefully this is helpful and makes sense! Jeff Anderson
signature.asc
Description: OpenPGP digital signature