如何在Django中访问上传的文件? [英] How to access uploaded files in Django?
问题描述
我在这里遵循了django的上传示例:
I followed the uploading example for django here:
现在,我要在浏览器中显示上载的文件(.jpg或.pdf).通过单击链接,浏览器打开URL:localhost:8000/media/documents/2014/08/04/test1.jpg 并且Django引发错误:当前网址media/documents/2014/08/04/test1.jpg与我定义的任何网址都不匹配.
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?
谢谢!
推荐答案
您需要启用django才能为您提供静态文件. Docs https://docs.djangoproject.com/en/dev/howto/static -files/. 特别是 https://docs.djangoproject.com/en/dev/howto/static-files/#serving-files-uploaded-by-a-user-during-development .
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 .
这篇关于如何在Django中访问上传的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!