1.根urls.py
文件中
from django.contrib import admin
from django.urls import path, include, re_path
from django.views.static import serve
from django.conf import settingsurlpatterns = [# path('admin/', admin.site.urls),path('api/shipper/', include('apps.shipper.urls')),re_path(r"^media/(?P<path>.*)$", serve, {'document_root': settings.MEDIA_ROOT}, name='media')
]
2.settings.py
文件中
UPLOAD_PATH = 'upload/'MEDIA_ROOT = BASE_DIR / 'media'
MEDIA_URL = '/media/'
3.效果