参考链接:
Django1.11官方文档
Django静态文件服务
- install app
django.contrib.staticfiles - 在settings.py中设置
STATIC_URL和STATICFILES_DIRS - template中使用静态文件可以直接使用绝对路径请求或者使用static标签(需在文件开头
{% load static %})
./manage.py runserver会自动完成对静态文件的路由
如果使用uwsgi则不会自动完成对静态文件的路由,可以手动加上
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Debug要设置为true
生产环境中的静态文件服务
The basic outline of putting static files into production is simple: run the
collectstaticcommand when static files change, then arrange for the collected static files directory (STATIC_ROOT) to be moved to the static file server and served.