Django的自定义模板

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chengqiuming/article/details/85028741

一 自定义模板和静态文件位置

二 改造自定义模板位置

1 修改mysite/mysite/settings.py

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        # 定义模板文件的位置,模板文件位于根目录的templates目录下
        'DIRS': [os.path.join(BASE_DIR, 'templates'),],
        # 不再允许Django按照默认方式寻找模板文件
        'APP_DIRS': False,
        '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',
            ],
        },
    },
]

2 改造后的目录结构——将blog下的模板都移动根目录下

三 运行测试

1 启动服务

2 浏览http://localhost:8000/blog/

猜你喜欢

转载自blog.csdn.net/chengqiuming/article/details/85028741