参考实例: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 }), ]
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:django MEDIA_URL MEDIA_ROOT 用法 - Python技术站