参考实例:https://cloud.tencent.com/developer/article/1578874

 

1.在项目setting中具体配置:

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

 

2  在url.py 中配置路由

from bookweb.settings import MEDIA_ROOT, STATICFILES_ROOT
from django.views.static import serve


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