settings.py上传目录的配置
html代码
处理代码
上传完成后图片存放在配置文件的上级目录下
而upload文件下是空的
这种问题如何解决啊!谢谢各位!
黄舟2017-04-17 16:31:05
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.
怪我咯2017-04-17 16:31:05
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)
PHP中文网2017-04-17 16:31:05
Add: In your MEDIA_ROOT
中,你上传文件的文件夹默认是myapp/upload
,而你实际的文件夹位置是myapp/myapp/upload
,os.path.dirname(__file__)
的路径指的是项目文件夹的位置,即第一个myapp
.