How to access uploaded files in Django?

2019-09-09 22:01发布

问题:

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:

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 .