美文网首页
Django静态文件develop和deploy

Django静态文件develop和deploy

作者: loinliao | 来源:发表于2018-02-25 10:45 被阅读0次

参考链接:
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.

相关文章

网友评论

      本文标题:Django静态文件develop和deploy

      本文链接:https://www.haomeiwen.com/subject/grulxftx.html