Почему я получаю TemplateDoesNotExist в /rapport/?
Я хотел бы просмотреть мою домашнюю страницу/индексный вид, но я продолжаю получать эту ошибку, что мне нужно сделать, чтобы избавиться от этого сообщения об ошибке ниже? Любая помощь будет принята с благодарностью. Вот сообщение об ошибке:
TemplateDoesNotExist at /rapport/
rapport/index.html, rapport/description_list.html
Request Method: GET
Request URL: http://127.0.0.1:8000/rapport/
Django Version: 4.0.4
Exception Type: TemplateDoesNotExist
Exception Value:
rapport/index.html, rapport/description_list.html
Exception Location: C:\Users\sbyeg\anaconda3\envs\new_env\lib\site-packages\django\template\loader.py, line 47, in select_template
Python Executable: C:\Users\sbyeg\anaconda3\envs\new_env\python.exe
Python Version: 3.8.6
Python Path:
['C:\\Users\\sbyeg\\django_projects\\rship',
'C:\\Users\\sbyeg\\anaconda3\\envs\\new_env\\python38.zip',
'C:\\Users\\sbyeg\\anaconda3\\envs\\new_env\\DLLs',
'C:\\Users\\sbyeg\\anaconda3\\envs\\new_env\\lib',
'C:\\Users\\sbyeg\\anaconda3\\envs\\new_env',
'C:\\Users\\sbyeg\\AppData\\Roaming\\Python\\Python38\\site-packages',
'C:\\Users\\sbyeg\\AppData\\Roaming\\Python\\Python38\\site-packages\\win32',
'C:\\Users\\sbyeg\\AppData\\Roaming\\Python\\Python38\\site-packages\\win32\\lib',
'C:\\Users\\sbyeg\\AppData\\Roaming\\Python\\Python38\\site-packages\\Pythonwin',
'C:\\Users\\sbyeg\\anaconda3\\envs\\new_env\\lib\\site-packages',
'C:\\Users\\sbyeg\\anaconda3\\envs\\new_env\\lib\\site-packages\\win32',
'C:\\Users\\sbyeg\\anaconda3\\envs\\new_env\\lib\\site-packages\\win32\\lib',
'C:\\Users\\sbyeg\\anaconda3\\envs\\new_env\\lib\\site-packages\\Pythonwin']
Server time: Mon, 07 Nov 2022 12:32:56 +0300
Вот мой код:
views.py
from django.shortcuts import render
from django.urls import reverse
from django.views import generic
from .models import Description
# Create your views here.
class IndexView(generic.ListView):
template_name = 'rapport/index.html'
context_object_name = 'description_list'
def get_queryset(self):
"""Return the last five keyed entries"""
return Description.objects.order_by('-event_date')[:5]
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.IndexView.as_view(), name='index'),
шаблонindex.html
{% extends "base_generic.html" %}
{% block content %}
<h1>Description List</h1>
<ul>
{% if description_list %}
{% for description in description_list %}
<li>
<a href="{{ description.get_absolute_url }}">{{ description.title }}</a>
</li>
{% endfor %}
</ul>
{% else %}
<p>There are no entries in the repository.</p>
{% endif %}
{% endblock %}
]
models.py
from django.db import models
from django.urls import reverse # Used to generate URLs by reversing the URL patterns
import datetime
# Create your models here.
class Description(models.Model):
title = models.CharField(max_length=200)
description_text = models.TextField(max_length=400, help_text='Enter a brief description of your entry' )
reminder_date = models.DateTimeField('date to be reminded')
event_date = models.DateTimeField('date of event')
def __str__(self):
return self.title #, #self.reminder_date, self.event_date
def is_upcoming(self):
return self.event_date <= timezone.now() + datetime.timedelta(days=30)
def get_absolute_url(self):
"""Returns the URL to access a detail record of this description."""
return reverse('description-detail', args=[str(self.id)])
class Meta:
ordering = ['event_date']
settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [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',
],
},
},
]
если информации недостаточно, свяжитесь со мной, чтобы узнать, что вам нужно, чтобы помочь в устранении этого сообщения об ошибке.
Изменить это:
'DIRS': [BASE_DIR/"templates"],
К этому:
'DIRS': [os.path.join(BASE_DIR,'rapport','templates')],
Примечание: папка templates должна находиться внутри вашего проекта или приложения.