settings
# MEDIA 存放路径
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# MEDIA 路由前缀
MEDIA_URL = "/media/"
urls.py
urlpatterns = [
# 匹配media路由
re_path(r"^media/(?P<path>.*)$", serve, {'document_root': settings.MEDIA_ROOT}, name='media')
]
访问
http://127.0.0.1:8000/media/qrcode.png