TemplateDoesNotExist at /new_topic/

I’m working out of a text book Python Crash Course third edition in chapters 18 and 19. I writing the code word for word line by line. I believe my issue is in views.py. When I run python manage.py runserver the browser opens to localhost:8000. But when I try to click on new topic link I get the error above. Here is my views.py code

from django.http import HttpResponseRedirect

#from importlib.metadata import EntryPoints, entry_points
from django.shortcuts import render, redirect
#from pkg_resources import EntryPoint

Create your views here.

from .models import Topic, Entry
from .forms import TopicForm, EntryForm

def index(request):
“”“The home page for learning Log.”“”
return render(request, ‘learning_logs/index.html’)

def topics(request):
“”“Show all topics.”“”

topics = Topic.objects.order_by('date_added')
context = {'topics': topics}
return render(request, 'learning_logs/topics.html', context)

def topic(request, topic_id):
“”“Show a single topic and all its entries.”“”
topic = Topic.objects.get(id=topic_id)
entries = topic.entry_set.order_by(‘-date_added’)
context = {‘topic’: topic, ‘entries’: entries}
return render(request, ‘learning_logs/topic.html’, context)

def new_topic(request):
“”“Add a new topic”“”
if request.method != ‘POST’:
# No data submitted; create a blank form.
form = TopicForm()
# POST data submitted; process data.
form = TopicForm(data=request.POST)
if form.is_valid():
return redirect(‘learning_logs:topics’)
# Display a blank or invalid form.
context = {‘form: form’}
return render(request, ‘learning_logs/new_topic.html’, context)

def new_entry(request, topic_id):
“”“Add a new entry for a particular topic.”“”
topic = Topic.objects.get(id=topic_id)

if request.method != 'POST':
# No data submitted; create a blank form.
    form = EntryForm()
    # POST data submitted; process data.
    form = EntryForm(data=request.POST)
    if form.is_valid():
        new_entry = form.save(commit=False)
        new_entry.topic = topic
        return redirect('learning_logs:topic', topic_id=topic_id)

def edit_entry(request, entry_id):
“”“Edit an existing entry.”“”
entry = Entry.objects.get(id=entry_id)
topic = entry.topic

if request.method !='POST':
    # Initial request; pre-fill form with current entry.
    form = EntryForm(instanc=entry)
    # Post data submitted; process data.
    form = EntryForm(instance=entry, data=request.POST)
    if form.is_valid():
        return redirect('learning_logs:topic', topic_id=topic.id)
# Display a blank or invalid form.
context = {'entry': entry, 'topic': topic, 'form': form}
return render(request, 'learning_logs/edit_entry.html', context)

Here is my learning_logs/urls code

Blo"““Define URL patterns for learning_logs.””"

from django.urls import path

from . import views

app_name = ‘learning_logs’
urlpatterns = [
# Home page
path(‘’, views.index, name=“index”),
# Page that shows all topics.
path(‘topics/’, views.topics, name=‘topics’),

# Detail page for a single topic.
path('topics/<int:topic_id>/', views.topic, name='topic'),
# Page for adding a new topic,\
path('new_topic/', views.new_topic, name='new_topic'),

# Page for adding a new entry
path('new_entry/<int:topic_id>/', views.new_entry, name='new_entry'),

# page for editing an entry.
path('edit_entry/<int:entry_id>/', views.edit_entry, name='edit_entry'),


A couple things -

  • When posting code here, enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. Do this for each file that you’re posting here.

  • There’s more information that gets printed than just the name of the error. Whenever you’re asking for help here, always include the complete error, including the full traceback. (Also, surround this information between lines of ``` just like the code.)

  • Show your directory structure, including the location of your template files.

  • Post your TEMPLATES setting from your settings.py file.