python - django上传文件没有到配置文件夹中去!
天蓬老师
天蓬老师 2017-04-17 16:29:05
0
3
584

settings.py上传目录的配置

html代码
处理代码

上传完成后图片存放在配置文件的上级目录下

而upload文件下是空的

这种问题如何解决啊!谢谢各位!
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(3)
黄舟

You handle the uploading and storage by yourself. How to save the files and where to store them are all up to you.
You save the file directly with the file name as the path, which is of course in the project directory. You can introduce the media path through the settings file, then splice the file name, and then save the file.

If you use django admin to save the file, the file will be stored in the directory specified by the media.

In addition, you can also use the upload file form to achieve this.

刘奇

In fact, @daizhan has basically finished the answer, I will only post some of my own configuration
setting files

# Media files (user-uploaded files)
MEDIA_ROOT = "your/path/"
MEDIA_URL = "/media/"

urls file

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Ty80

Add: In your MEDIA_ROOT中,你上传文件的文件夹默认是myapp/upload,而你实际的文件夹位置是myapp/myapp/upload,os.path.dirname(__file__)的路径指的是项目文件夹的位置,即第一个myapp.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!