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?

1 Answer 1

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.