Template locating issue

Newb here, getting the following error:

need help debugging it.

I have the edit.html in a folder, with my base html but it cannot find it.

urls.py

from django.urls import path
from . import views
from django.contrib.auth import views as auth_views

urlpatterns = [
path(‘’,views.home,name=‘CMS-home’),
path(‘about/’,views.about,name=‘CMS-about’),
path(‘HHAProg/’,views.HHAProg,name=‘CMS-HHAProg’),
path(‘int:pk’, views.DetailView.as_view(),name=‘entry’),
path(‘submit’,views.CreateView.as_view(),name=‘submit’)
]

models.py

from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
from django.urls import reverse

class Post(models.Model):
title = models.CharField(max_length=100)
content = models.TextField()
date_posted = models.DateTimeField(default=timezone.now)
author = models.ForeignKey(User, on_delete=models.CASCADE)

def __str__(self):
    return self.title

class Estudiante(models.Model):
name = models.CharField(max_length=40,blank=False)
def str(self):
return self.name

class Programa(models.Model):
title = models.CharField(max_length=49,blank=False)
def str(self):
return self.title

class Casa(models.Model):
student = models.ForeignKey(Estudiante, on_delete=models.PROTECT)
cohort = models.ForeignKey(Programa, on_delete=models.PROTECT)
phoneNum = models.CharField(max_length=15,blank=False)
emailAddr = models.CharField(max_length=44,blank=False)
homeAddr = models.CharField(max_length=44,blank=False)
ciudad = models.CharField(max_length=25,blank=False)
estadio = models.CharField(max_length=3,blank=False)
zipC = models.CharField(max_length=10,blank=False)
def str(self):
return self.title
def get_absolute_url(self):
return reverse(‘entry’,kwargs={‘pk’: self.pk})

views.py

from django.shortcuts import render,HttpResponse
from . import models
from . models import Post, Casa, Estudiante, Programa
from django.views.generic import ListView,DetailView,CreateView
from django.core.paginator import Paginator

Created views here.

def home(request):
context = {
‘posts’ : Post.objects.all()
}
return render(request,‘CMS/home.html’,context)

def about(request):
return render(request,‘CMS/about.html’,{‘title’: ‘About’})

def HHAProg(request):
return render(request,‘CMS/HHAProg.html’,{‘title’: ‘HHAProg’})

class IndexView(ListView):
context_object_name =‘casa’
template_name = ‘home.html’

def get_queryset(self):
    return models.Casa.objects.all()

class DetailView(DetailView):
context_object_name =‘casa’
model=models.Casa
template_name = ‘entry.html’

class CreateView(CreateView):
model= models.Casa
fields = [‘student’,‘cohort’,‘phoneNum’,‘emailAddr’,‘homeAddr’,‘ciudad’,‘estadio’,‘zipC’]
template_name =‘edit.html’

First, a side note - whenever you’re posting code here, please enclose the code between lines of three backtick - ` characters to force the forum software to keep it properly formatted. That means that you would have a line of ```, then the code, then another line of ```.
Also, when you copy/paste your tracebacks, enclose them between the lines of ``` as well.
(Please don’t post images here. They’re unreadable on many devices and cannot be copied into responses to highlight key issues.)

Now to your real questions.

What directory is your edit.html file in?

What does your TEMPLATES setting in your settings.py file look like?

1 Like

Ken,

Gracias!! I appreciate you helping out, giving a few pointers already about how to pose questions to the forum.

Here is my tree structure

├── CMS
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-38.pyc
│   │   ├── admin.cpython-38.pyc
│   │   ├── apps.cpython-38.pyc
│   │   ├── models.cpython-38.pyc
│   │   ├── urls.cpython-38.pyc
│   │   └── views.cpython-38.pyc
│   ├── admin.py
│   ├── apps.py
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   ├── __init__.py
│   │   └── __pycache__
│   │       ├── 0001_initial.cpython-38.pyc
│   │       └── __init__.cpython-38.pyc
│   ├── models.py
│   ├── static
│   │   └── CMS
│   │       └── main.css
│   ├── templates
│   │   └── CMS
│   │       ├── HHAProg.html
│   │       ├── about.html
│   │       ├── base.html
│   │       ├── edit.html
│   │       ├── entry.html
│   │       └── home.html
│   ├── tests.py
│   ├── urls.py
│   └── views.py
----
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
            ],
        },
    },
]

traceback:

System check identified no issues (0 silenced).
April 27, 2022 - 19:43:37
Django version 2.2.12, using settings 'Ecuentro_CMS.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[27/Apr/2022 19:43:48] "GET / HTTP/1.1" 200 3222
Not Found: /favicon.ico
[27/Apr/2022 19:43:48] "GET /favicon.ico HTTP/1.1" 404 3323
Internal Server Error: /submit
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/usr/lib/python3/dist-packages/django/core/handlers/base.py", line 145, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/lib/python3/dist-packages/django/core/handlers/base.py", line 143, in _get_response
    response = response.render()
  File "/usr/lib/python3/dist-packages/django/template/response.py", line 106, in render
    self.content = self.rendered_content
  File "/usr/lib/python3/dist-packages/django/template/response.py", line 81, in rendered_content
    template = self.resolve_template(self.template_name)
  File "/usr/lib/python3/dist-packages/django/template/response.py", line 63, in resolve_template
    return select_template(template, using=self.using)
  File "/usr/lib/python3/dist-packages/django/template/loader.py", line 47, in select_template
    raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)
django.template.exceptions.TemplateDoesNotExist: edit.html
[27/Apr/2022 19:43:56] "GET /submit HTTP/1.1" 500 80690

Side note - you need to make sure you’re using the backtick - ` character and not the apostrophe - '. (You can edit your reply if you’d like.)

For clarity, CMS is the name of the Django app and it resides within your project directory?

And the edit.html is directly under the CMS/templates directory and not under the CMS/templates/CMS directory?

Ken,

Thank you very much for the character clarification!!

CMS is the name of the django app it resides the whole structure.

└── Encuentro_CMS
    ├── CMS
    │   ├── __init__.py
    │   ├── __pycache__
    │   │   ├── __init__.cpython-38.pyc
    │   │   ├── admin.cpython-38.pyc
    │   │   ├── apps.cpython-38.pyc
    │   │   ├── models.cpython-38.pyc
    │   │   ├── urls.cpython-38.pyc
    │   │   └── views.cpython-38.pyc
    │   ├── admin.py
    │   ├── apps.py
    │   ├── migrations
    │   │   ├── 0001_initial.py
    │   │   ├── __init__.py
    │   │   └── __pycache__
    │   │       ├── 0001_initial.cpython-38.pyc
    │   │       └── __init__.cpython-38.pyc
    │   ├── models.py
    │   ├── static
    │   │   └── CMS
    │   │       └── main.css
    │   ├── templates
    │   │   └── CMS
    │   │       ├── HHAProg.html
    │   │       ├── about.html
    │   │       ├── base.html
    │   │       ├── edit.html
    │   │       ├── entry.html
    │   │       └── home.html
    │   ├── tests.py
    │   ├── urls.py
    │   └── views.py
    ├── Ecuentro_CMS
    │   ├── __init__.py
    │   ├── __pycache__
    │   │   ├── __init__.cpython-38.pyc
    │   │   ├── settings.cpython-38.pyc
    │   │   ├── urls.cpython-38.pyc
    │   │   └── wsgi.cpython-38.pyc
    │   ├── settings.py
    │   ├── urls.py
    │   └── wsgi.py
    ├── db.sqlite3
    ├── manage.py
    └── users
        ├── __init__.py
        ├── __pycache__
        │   ├── __init__.cpython-38.pyc
        │   ├── admin.cpython-38.pyc
        │   ├── apps.cpython-38.pyc
        │   ├── forms.cpython-38.pyc
        │   ├── models.cpython-38.pyc
        │   └── views.cpython-38.pyc
        ├── admin.py
        ├── apps.py
        ├── forms.py
        ├── migrations
        │   ├── __init__.py
        │   └── __pycache__
        │       └── __init__.cpython-38.pyc
        ├── models.py
        ├── templates
        │   └── users
        │       ├── login.html
        │       ├── logout.html
        │       └── register.html
        ├── tests.py
        └── views.py


Ok, so since edit.html resides within the CMS directory in the templates directory, your reference to it would be CMS/edit.html. (Note: that’s what you have in your references to about.html and home.html above.)

1 Like

Ken,

I believe it is finding the page now properly, however it is throwing a different error.

I will try and debug it, or post another reply!

1 Like