0

In settings.py I got media_url = '/media/' and static_url = '/static/'

In the urls.py I got:

(r'^media/(?P<path>.*)$', 'django.views.static.serve',{'document_root': settings.MEDIA_ROOT,'show_indexes': True}),
(r'^static/(?P<path>.*)$', 'django.views.static.serve',{'document_root': settings.STATIC_ROOT,'show_indexes': True}),

When I try to open localhost/media/ django correctly loads images placed in the media direcotry. But when I try to go to /static/ I get the:

Request Method: GET
Request URL:    localhost/static/
Directory indexes are not allowed here.

But, when in the setting.py I change static_url = '/sssstatic/', then the localhost/static/ works fine.

What's the issue here?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
meso_2600
  • 1,940
  • 5
  • 25
  • 50

1 Answers1

4

Django automatically serves STATIC_URL when DEBUG=True. You don't specify it in urls.py. Or, if you do need to specify it for some reason you use:

from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns += staticfiles_urlpatterns()
Chris Pratt
  • 232,153
  • 36
  • 385
  • 444