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!

1 Answer 1

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 .

Sign up to request clarification or add additional context in comments.

3 Comments

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 for sub-directories is the same, just use your MEDIA URL/you-new-subdirectory
Ok I solved the problem. I had a mistake in my MEDIA_ROOT path... Now it is working fine!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.