Hello,
It is the first time I import datas from my database managed with Wamp. I can not reach to import on Django datas from specific colums of my database. It is about a digital library which I want to display the catalog on the homepage. Here is the error message released on my navigator opened at the locally homepage of my project called “sgbj” :
TemplateDoesNotExist at /
books/books.html
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 5.0.2
Exception Type: TemplateDoesNotExist
Exception Value: books/books.html
Exception Location: C:\Users\my_username\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\backends\django.py, line 84, in reraise
Raised during: sgbj.views.home_view
Python Executable: C:Users\my_username\AppData\Local\Programs\Python\Python312\python.exe
Python Version: 3.12.1
Template-loader postmortem
Django tried loading these templates, in this order:
Using engine django:
This engine did not provide a list of tried templates.
Error during template rendering
In template C:\cygwin64\home\my_username\DJANGO\sgbj\templates\home.html, error at line 7
books/books.html
1 {% extends 'template_base.html' %}
2
3 {% block titre %}Page d'accueil{% endblock %}
4
5 {% block contenu %}
6 <h1>Ma bibliothèque</h1>
7 {% include 'books/books.html' %}
8 {% endblock %}
In a first time, I checked the path of my application called “books”. The path contained in the urls.py file of my application “books” is this one :
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('', views.books_home_view, name='home'),
]
I effectively want to display the view of my application “books” on the homepage of my project “sgbj”.
In a second time, I checked my code in the models.py field of my application “books” :
from django.db import models
class Book(models.Model):
lastname = models.CharField(max_length=100)
firstname = models.CharField(max_length=100)
title = models.CharField(max_length=200)
isbn = models.CharField(max_length=20)
def __str__(self):
return self.title
Then, the views.py field of my app “books” :
from django.shortcuts import render
from books.models import Book
def books_home_view(request):
books = Book.objects.all()
return render(request, 'books/books.html', context={'books': books})
And finally, here is the code of the homepage of my “sgbj” project where I included books.html of my app “books” :
{% extends 'template_base.html' %}
{% block titre %}Page d'accueil{% endblock %}
{% block contenu %}
<h1>Ma bibliothèque</h1>
{% include 'books/books.html' %}
{% endblock %}
I was forgetting to specify the templates variables I added in settings.py field of my “sgbj” project :
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['books/books.html', 'C:\\cygwin64\\home\\my_username\\DJANGO\\sgbj\\books\\templates', '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',
],
},
},
]
I hope I have provided you with sufficient code so that you can easily identify why I am unable to display my library catalog. Thank you in advance…
Relf