Django静态文件develop和deploy

参考链接:
Django1.11官方文档

Django静态文件服务

  1. install app django.contrib.staticfiles
  2. 在settings.py中设置STATIC_URLSTATICFILES_DIRS
  3. 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 collectstatic command when static files change, then arrange for the collected static files directory (STATIC_ROOT) to be moved to the static file server and served.

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容