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