Download from MEDIA_ROOT not working

I am trying to make one Userto download a file (in some language) and another Userto load it so that it can translate it.

I set the media root and media url:

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

When someone uploads a file through form, the file appears in project/media/file. But the problem is that if I try to click a file or type url /project/media/file.extension, it raises

Page not found (404)
Request Method: GET
Request URL:    http://127.0.0.1:8000/media/File_-_Psychos_lZB1D1N.mp3
Using the URLconf defined in SolutionsForLanguages_2.urls, Django tried these URL patterns, in this order:

http://127.0.0.1:8000/media/File_-_Psychos_lZB1D1N.mp3

What to do to make it work?

+4
source share
1 answer

, ? urls.py, Django static/ media/.

if settings.DEBUG:
    from django.contrib.staticfiles.urls import staticfiles_urlpatterns
    from django.conf.urls.static import static

    urlpatterns += staticfiles_urlpatterns()
    urlpatterns += static(
        settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
+4

All Articles