一、环境搭建
-
建立项目
django-admin startproject project_demo
-
配置数据库(以MySQL为例)
# settings.py DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'django_file4', 'USER': 'root', 'PASSWORD': '123', 'HOST': '192.168.31.151', 'PORT': '3306', } }
-
建立模型
class UploadFileImg(models.Model): file = models.FileField(upload_to='files/') img = models.ImageField(upload_to='imgs/') desc = models.Ch