my deposal directory for my html files is C:\learning_log\learning_logs\templates\learning_log
Directory of C:\learning_log\learning_logs\templates\learning_logs
base.html
index.html
topics.html
# My topics.html
{% extends “learning_logs/base.html” %}
{% block content %}
Topics
{% for topic in topics %}* {{ topic }}
{% empty %}* No topics have been added yet.
{% endfor %}
{% endblock content %}
My views.py
""" From learning_log/learning_logs """
from django.shortcuts import render
from .models import Topic
# Create your views here.
def index(request):
""" the home page from learning_log """
return render(request, 'learning_logs/index.html')
#def topics(request):
# """show all topics"""
# topics = Topic.objects.order_by('date_added') #date_added
# context = {'topics':topics}
# return render(request,'learning_logs/topics.html', context)
# ADD test 01/01/2024
def topics(request):
"""show all topics"""
topics = Topic.objects.order_by('date_added')
print(topics) # Add this line for debugging
context = {'topics': topics}
# return render(request, 'templates/learning_logs/topics.html', context)
return render(request, 'learning_logs/topics.html', context)
#The runserver find the data requested (200)
C:\learning_log>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks…
System check identified no issues (0 silenced).
January 02, 2024 - 21:52:08
Django version 3.2.18, using settings ‘learning_log.settings’
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
<QuerySet [<Topic: Topic 1>, <Topic: Topic 2>]>
[02/Jan/2024 21:52:23] “GET /topics/ HTTP/1.1” 200 86
but the display on my browser is
[learning_logs](http://127.0.0.1:8000/) - [topics](http://127.0.0.1:8000/topics/)" }‘’’
#My setting.py contain
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’,
],
}
}
]
Sseams that the data base is working fine
C:\learning_log>python manage.py shell
Python 3.11.1 (tags/v3.11.1:a7a450f, Dec 6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
(InteractiveConsole)
> > > from learning_logs.models import Topic
> > > first_topic = Topic.objects.first()
> > > print(first_topic)
> > > Topic 1
> > > specific_topic = Topic.objects.get(id=1)
> > > print(specific_topic)
> > > Topic 1
Seams that django does not find his views.py to display the informations to the browser screen