标签:att settings 导入 路径 src static pre imp setting
1.setting.py配置#用户文件上传至media
MEDIA_URL=‘/media/‘
MEDIA_ROOT=os.path.join(BASE_DIR,"media")
2.url.py配置
#导入正则路径
from django.urls import re_path
from django.views.static import serve
from MyAPP.settings import MEDIA_ROOT
urlpatterns=[
#添加media正则路径
re_path(r‘^media/(?P<path>.*)$‘, serve, {‘document_root‘:MEDIA_ROOT}),
]
3.templates文件配置
<img src="/media/{{路径}}">
标签:att settings 导入 路径 src static pre imp setting
原文地址:http://blog.51cto.com/13803166/2300687