1.django之静态文件路径设置

2017-12-04  本文已影响0人  马梦里

1.template

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR表示项目的根目录
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')
在根目录创建文件夹templates/mamengli_blog,放置应用所需的模板文件;

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [TEMPLATE_DIR,],
        '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',
            ],
        },
    },
]

DIRS后面加入模板变量,那么在视图函数中使用模板时,系统会自动在DIRS中进行查找;

上一篇 下一篇

猜你喜欢

热点阅读