[Django]-[django]when debug=false,MEDIA_URL returns not found

6๐Ÿ‘

โœ…

As per the documentation:

This helper function works only in debug mode and only if the given
prefix is local (e.g. /media/) and not a URL (e.g.
http://media.example.com/).

With the helper function they mention being: + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Setting up static & media files for nginx in production very simple, DigitalOcean has a great guide. The Static part is just a couple lines:

    location /media/ {
        root /home/sammy/myproject;
    }
๐Ÿ‘คJens Astrup

0๐Ÿ‘

Set this code below to "urls.py" to show media files in "DEBUG = False":

# "urls.py"

from django.conf.urls import url
from django.views.static import serve
from django.conf import settings

urlpatterns = [
    # ...
    url(r'^media/(?P<path>.*)$', serve,{'document_root': settings.MEDIA_ROOT}),
]

Leave a comment