django static template file upload and download configuration

settings.py

STATIC_URL = '/api/static/'
MEDIA_URL = '/api/media/'
# MEDIA_ROOT = 'media'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static')
]

urls.py

from django.conf.urls import url, include
from django.contrib import admin
from django.views.static import serve
from leapin import defaults
from django.conf.urls.static import static

urlpatterns = [
    url(r'^api/admin/', admin.site.urls, name='admin'),
    url(r'^api/', include('less.api.urls', namespace='api')),
    # url(r'/api/media/', serve, {"document_root":defaults.MEDIA_ROOT})
] + static(defaults.MEDIA_URL, document_root=defaults.MEDIA_ROOT)

At this point the need to build a media file and place the file inside this package

Note that the path to the folder and media settings.py in the same path

eg:

 

 

 This configured the path, enter in your browser

http:127.0.0.1:8000/api/media/tests.xlsx/

At this time, it will download the template

Guess you like

Origin www.cnblogs.com/tangda/p/12214229.html