django 引用static templates

来源:互联网 发布:ubuntu关闭apache服务 编辑:程序博客网 时间:2024/05/17 23:47

引用static
 1. 在django project中创建 static文件夹
 2.settings.py中配置要在 STATIC_URL = '/static/'  下边 
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'), ]

3前端引用

{% load staticfiles %}
在 link script 等src 写 :
{%static 'xxx.css'%} 
{%static 'xxx.js'%}


应用templates

 TEMPLATES = [
     {
         'BACKEND': 'django.template.backends.django.DjangoTemplates',
         'DIRS': [os.path.join(BASE_DIR, 'templates')],
         'APP_DIRS': True,
         'OPTIONS': {
             'context_processors': [
                 'django.template.context_processors.debug',
                 'django.template.context_processors.request',
                 'django.contrib.auth.context_processors.auth',
                 'django.contrib.messages.context_processors.messages',
                 'django.core.context_processors.static',
             ],
         },
     },
  ]


 TEMPLATE_DIRS = (
     os.path.join(BASE_DIR, 'templates'),
 )
 

# 下面的会影响到admin的样式

STATIC_ROOT = 'static'STATIC_URL = '/static/'

原创粉丝点击