简体   繁体   中英

Django TemplateDoesNotExist {% extends base.html %} - where should template be?

I'm starting a very simple Django app but having trouble with extending an html file.

I have base.html and index.html both within my_site/my_app/templates/my_app .

ie my_site/my_app/templates/my_app/base.html and my_site/my_app/templates/my_app/index.html .

Within the index.html file I have {% extends 'base.html' %} .

My settings.py file has

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

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

But when I visit my index view at http://127.0.0.1:8000/index/ :

def index(request):
    return render(request, 'my_app/index.html')

I get the following error:

TemplateDoesNotExist at /index/
base.html
Request Method: GET
Request URL:    http://127.0.0.1:8000/index/
Django Version: 1.10.3
Exception Type: TemplateDoesNotExist
Exception Value: base.html

Do I have the base.html file saved in the wrong place or is it something else? I have not been able to solve this.

它应该在my_site / my_app / templates或my_site / templates中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM