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)
此时需要建一个media 文件 并将文件放在这个包里面
注意media文件夹的路径要和settings.py中的路径一致
eg:
这样就配置好了路径,在浏览器中输入
http:127.0.0.1:8000/api/media/tests.xlsx/
此时就将模版下载下来了