1

As stated in topic, my Django site media url is returning 404 after trying to access it. Everything was working flawless until I wanted to end the development process and set

DEBUG = True

in settings.py to have the site finished once and for all. When I change DEBUG back to

DEBUG = False

it works fine once again. I have no idea what's the problem, any suggestions?

0

1 Answer 1

8

This is by design: https://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-during-development

If you use django.contrib.staticfiles as explained above, runserver will do this automatically when DEBUG is set to True.

That being said, you can use the following workaround by modifying your urls.py:

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = patterns('',
    # ... the rest of your URLconf goes here ...
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
  + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Note that this is highly inefficient and not encouraged for production use. You should normally configure your web server (apache, nginx, etc) to serve your static and media content.

Sign up to request clarification or add additional context in comments.

2 Comments

Do I set it in the app urls.py or the site urls.py?
It would be the site's urls.py. Remember to add the import statements too.

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.