1.settings.py文件中配置
# 项目中存储上传文件的根目录[暂时配置],注意,uploads目录需要手动创建否则上传文件时报错
MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads')
# 访问上传文件的url地址前缀
MEDIA_URL = '/media/'
2.总路由配置
from django.conf import settings
from django.urls import path, re_path
from django.views.static import serve # serve表示处理找图片的逻辑
urlpatterns = [
re_path(r'media/(?P<path>.*)',serve,{'document_root':settings.MEDIA_ROOT})
]