Django允许media文件路径

2022-08-04 10:45:33 浏览数 (1)

代码语言:javascript复制
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
MEDIA_URL = '/media/'
代码语言:javascript复制
from django.urls import path, include, re_path
from django.views.static import serve
from mysite import settings
urlpatterns = [
    re_path(r"media/(?P<path>.*)$", serve, {'document_root': settings.MEDIA_ROOT})
]

0 人点赞