Django не может найти шаблон, хранящийся в app_name / templates / app_name - PullRequest
0 голосов
/ 28 мая 2020

Я пытаюсь создать сайт рецептов. У меня есть два приложения: account (данные для аутентификации пользователя) и recipe. Шаблоны для account хранятся в account/templates/registration. Django может найти их без проблем, мой вход, выход, регистрация и т.д. c представления работают без проблем. Однако в моем приложении с рецептами у меня есть одно простое представление:

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

Этот файл существует по адресу recipe/templates/recipe/index.html. Когда я пытаюсь получить к нему доступ, я получаю следующую ошибку:

Django tried loading these templates, in this order:

Using engine django:

django.template.loaders.filesystem.Loader: /Users/justinobrien/Desktop/recipeSite/website/templates/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Users/justinobrien/Desktop/recipeSite/website/account/templates/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Users/justinobrien/Desktop/recipeSite/env/lib/python3.6/site-packages/crispy_forms/templates/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Users/justinobrien/Desktop/recipeSite/env/lib/python3.6/site-packages/django/contrib/admin/templates/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Users/justinobrien/Desktop/recipeSite/env/lib/python3.6/site-packages/django/contrib/auth/templates/index.html (Source does not exist)

Ясно, что он не смотрит на правильный путь, я просто не уверен, как сказать ему, чтобы он смотрел туда?

Я также внес изменения в часть DIRS переменной TEMPLATES, чтобы Django мог найти базу. html файл, который я сохранил в project_root/templates/base.html:

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

Я думаю, это может вызвать проблему. Спасибо за любую помощь.

...