1

I followed the uploading example for django here:

Minimal Django File Upload Example

Now I want display the uploaded file (.jpg or .pdf) in the browser. By clicking on the link the browser opens the URL: localhost:8000/media/documents/2014/08/04/test1.jpg and Django throws an error: The current URL, media/documents/2014/08/04/test1.jpg, didn't match any of my defined urls.

How can I change the url-settings for my media files?

Thanks!

Community
  • 1
  • 1
work.b
  • 23
  • 1
  • 5

1 Answers1

3

You need to enable django to serve static files for you. Docs https://docs.djangoproject.com/en/dev/howto/static-files/ . This in particular https://docs.djangoproject.com/en/dev/howto/static-files/#serving-files-uploaded-by-a-user-during-development .

pavel_form
  • 1,760
  • 13
  • 14
  • ok I added `+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)`to the urls. Now it is working so far... Now I have to figure out how to use sub-directories... – work.b Aug 04 '14 at 14:34
  • 1
    @work.b for sub-directories is the same, just use your MEDIA URL/you-new-subdirectory – levi Aug 04 '14 at 16:21
  • Ok I solved the problem. I had a mistake in my MEDIA_ROOT path... Now it is working fine! – work.b Aug 05 '14 at 10:25