2

I'm using Python 2.7, Django 1.8 and apache server on my project. When I use DEBUG=True, on my develop server, uploaded images viewed very well on template, but when DEBUG=False, i get a 404 error. However static files work very well.

My setting.py look so:

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

MEDIA_URL = '/media/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

STATIC_URL = '/static/'

The urls.py looks like on this post:

if settings.DEBUG:
        urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

What i should change to make my media files work. Thanks.

Community
  • 1
  • 1
Zagorodniy Olexiy
  • 2,132
  • 3
  • 22
  • 47

1 Answers1

3

With debug turned off Django won't handle static files for you any more - your production web server (Apache or something) should take care of that. If you still need to server static locally (e.g. for testing without debug) you can run devserver in insecure mode:

manage.py runserver --insecure
P3zhman
  • 243
  • 3
  • 12