1、启用media

1.1 在url.py中进行配置

引用模块

from django.urls import path, re_path
from django.views.static import serve
from django.conf import settings

配置URL

urlpatterns = [
    re_path(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT}, name='media'),
]

1.2配置settings.py

#引用模块
import os
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_URL = "/media/"

2、Form方式上传文件


VIRIYA
1 声望0 粉丝