Pit encountered by python download file

Purpose: To download files directly through the url given by the backend.
Question: 404 (404 on local online).
Insert picture description here
I carefully checked the default.py file
. The relevant custom static directory has indeed been configured.

# 自定义静态目录
USERRES_URL = '%sUSERRES/' % SITE_URL
USERRES_ROOT = os.path.join(PROJECT_ROOT, 'USERRES')
DOWNLOAD_ROOT = os.path.join(PROJECT_ROOT, 'USERRES')
DOWNLOAD_URL = '%sdownload/' % SITE_URL

But the download function still does not work.
After investigation, it is found that the URL of the new framework is not added to the download static URL.

from django.views.static import serve
from config.default import DOWNLOAD_ROOT

# 全局生效
urlpatterns += [
    url(r'^download/(?P<path>.*)$',
        serve, {'document_root': DOWNLOAD_ROOT}),
]

After joining, both local and online downloads are normal.

Guess you like

Origin blog.csdn.net/qq_42631707/article/details/110138240