Django 建立文件上传文件夹路由

 

common.py 或者setting.py里面添加配置

UOLOAD_URL = 'upload/'
UOLOAD_ROOT = os.path.join(BASE_DIR.parent, 'upload')

 

配置url,

引入包:from django.views.static import serve
urlpatterns = [
    re_path(r'^upload/(?P<path>.*)$',serve, {"document_root": UOLOAD_ROOT}),
]

或者

urlpatterns = [
    # path('admin/', admin.site.urls),
    # 配置django-rest-framwork API路由
] + static(settings.UOLOAD_URL, document_root=settings.UOLOAD_ROOT)

 

posted @ 2021-12-14 16:41  fpc  阅读(135)  评论(0编辑  收藏  举报