标签:roo 结构 ext process 分享 .com bdc png 结构图
Django为了方便开发调试,debug模式下runserver会利用django.contrib.staticfiles应用自动部署资源服务,但是生产模式下(或Debug=True时),如果还想要Django提供资源服务,就必须明确提供资源相关的配置,使其承担资源服务。第一种形式:
1、项目设置中配置(settings.py)
STATIC_ROOT = os.path.join(BASE_DIR, ‘static‘)
2、在全局url中配置(urls.py)
re_path(r‘^static/(?P<path>.*)$‘, static.serve, {‘document_root‘: settings.STATIC_ROOT})
3、执行资源搜集命令
python manage.py collectstatic
4、模板中使用
<link rel="stylesheet" type="text/css" href="{% static ‘mysite/style.css‘ %}" />
5、项目结构图
第二种形式:
1、在应用url中配置(urls.py)
re_path(r‘^static/(?P<path>.*)$‘, static.serve, {‘document_root‘: ‘./static/‘}, name=‘static‘)
2、模板中使用
<link rel="stylesheet" type="text/css" href="{% url ‘mysite:static‘ ‘mysite/style.css‘ %}" />
3、项目结构图
参考:https://docs.djangoproject.com/zh-hans/2.0/ref/contrib/staticfiles/
标签:roo 结构 ext process 分享 .com bdc png 结构图
原文地址:http://blog.51cto.com/xuke1668/2147243