Django使用应用程序目录中的html模板

时间:2017-04-07 19:29:25

标签: python django

我使用django 1.10.3 我想从app dir使用html模板 我使用文件夹模板和testPage.html

创建app test_page

在view.py

from django.shortcuts import render

def page(request):
     return render(request, 'test_page/testPage.html', locals())

在settings.py中

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',
        ],
    },
},
]

但它不起作用。 如何从dir应用程序中使用html模板?

2 个答案:

答案 0 :(得分:1)

目录结构:

project/
    test_page/
        templates/
            test_page/
                test_page.html

答案 1 :(得分:0)

当您的项目名称为django_server且应用名称为myapp时,使用python manage.py startapp myapp生成,结构应为:

django_server/
myapp/
    templates/
         test_page/
              testPage.html