代码语言: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})
]