4

I'm trying to make one User to upload a file (in some language) and another User to download it so they can translate it.

I've set media root adn media url:

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

When someone uploads a file through form, the file appeares in project/media/file. But the problem is that if I try to click on the file or type an 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?

Milano
  • 18,048
  • 37
  • 153
  • 353

1 Answers1

4

I am guessing you are on the development server? Add this to the urls.py config file to tell Django's development server to serve static/ and media/ files too.

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)
C14L
  • 12,153
  • 4
  • 39
  • 52