Django:下载上传的文件 [英] Django: Downloading uploaded files

查看:108
本文介绍了Django:下载上传的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此问题中有形式详细信息 Django:将文件添加到表单中会给出多个参数错误

I have form details in this question Django: Adding files to a form gives multiple argument error

如何下​​载已上传的文件。当我去编辑表单的视图时,我可以看到上传的文件url,但它没有下载。
开发和生产模式下哪些设置要更改?

How to download the uploaded file. When i go to edit view of the form, i can see uploaded file url, but its not downloading. What setting to be changed for development and production mode?

点击链接时出错:

Page not found (404)
Request Method:     GET
Request URL:    http://127.0.0.1:8000/media/Certificate.docx

Using the URLconf defined in tiktant.urls, Django tried these URL patterns, in this order:

    ^ ^$ [name='home']
    ^ ^login/$ [name='login']
    ^ ^logout/$ [name='logout']
    ^ ^logout_then_login/$ [name='logout_then_login']
    ^ ^dashboard/$ [name='dashboard'] 
The current URL, media/Certificate.docx, didn't match any of these.


推荐答案

媒体网址未显示在根网址中。 py文件。您需要在urls.py文件中添加以下代码以启用相同的操作。

The media url is not showing in the root urls.py file. You need to add the below code in the urls.py file to enable the same.

if settings.DEBUG:
    from django.conf.urls.static import static
    urlpatterns += static(settings.MEDIA_URL,
                          document_root=settings.MEDIA_ROOT)

注意:请不要忘记在settings.py文件中添加MEDIA_ROOT和MEDIA_URL。要下载文件,您需要编写更多的代码。

Note: Please don't forget to add the MEDIA_ROOT and MEDIA_URL in settings.py file. For downloading a file, you need to write some more code.

这篇关于Django:下载上传的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆