Edit entry URL not linking correctly in Django (Python crash course 3rd Ed.)

I’m working through the Python Crash Course book by Eric Matthes. In Chapter 19 i start to run into problems. The ‘Edit Entry’ section does not load correctly when clicking the link. The link displays where it should, with the text that it should, but when clicking the link i get this message in my browser:

Page not found (404)
Request Method: GET
Request URL:    http://localhost:8000/topics/1/%7Burl%20'learning_logs:edit_entry'%20entry.id%7D
Using the URLconf defined in ll_project.urls, Django tried these URL patterns, in this order:

admin/
[name='index']
topics/ [name='topics']
topics/<int:topic_id>/ [name='topic']
new_topic/ [name='new_topic']
new_entry/<int:topic_id>/ [name='new_entry']
edit_entry/<int:entry_id>/ [name='edit_entry']
The current path, topics/1/{url 'learning_logs:edit_entry' entry.id}, didn’t match any of these.

runserver shows this output in the terminal:

Not Found: /topics/1/{url 'learning_logs:edit_entry' entry.id}
[10/Jul/2024 09:49:24] "GET /topics/1/%7Burl%20'learning_logs:edit_entry'%20entry.id%7D HTTP/1.1" 404 3357

Django Version 5.0.6
Python Version 3.12.4

Here is the relevant code i have so far in the project for reference:

**learning_logs/views.py:**

from django.shortcuts import render, redirect
from .models import Topic, Entry
from .forms import TopicForm, EntryForm

def index(request):
        ''' The home page for learning_logs '''
    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 it's 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()
    else:
        # POST data submitted; process data.
        form=TopicForm(data=request.POST)
        if form.is_valid():
            form.save()
            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()
    else:
        # POST data submitted, process data
        form=EntryForm(data=request.POST)
    if form.is_valid():
        new_entry=form.save(commit=False)
        new_entry.topic=topic
        new_entry.save()
        return redirect('learning_logs:topic', topic_id=topic_id)
        
    # Display a blank or invalid form
    context = {'topic':topic,'form': form}
    return render(request,'learning_logs/new_entry.html', context)

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(instance=entry)
    
    else:
        # POST data submitted; process data
        form=EntryForm(instance=entry, data=request.POST)
        if form.is_valid():
            form.save()
            return redirect('learning_logs:topic', topic_id=topic.id)
        
    context={'entry':entry,'topic': topic,'form': form}
    return render(request,'learning_logs/edit_entry.html',context)`



**learning_logs/urls.py:**




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 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'),`



**learning_logs/templates/edit_entry.html:**



{% extends "learning_logs/base.html" %}

{% block content %}

  <p><a href="{% url 'learning_logs:topic' topic.id %}">{{ topic }}</a></p>

  <p>Add a new entry:</p>
  <form action="{% url 'learning_logs:new_entry' topic.id %}" method='post'>
    {% csrf_token %}
    {{ form.as_div }}
    <button name='Submit'>Add entry</button>
  </form>

{% endblock content %}`



**learning_logs/templates/topic.html:**

{% extends 'learning_logs/index.html' %}

{% block content %}

  <p>Topic: {{topic.text}}</p>

  <p>Entries:</p>
  <p>
    <a href="{% url 'learning_logs:new_entry' topic.id %}">Add new entry</a>
  </p>

  <ul>
    {% for entry in entries %}</ul>
      <li>
        <p>{{ entry.date_added|date:'M d, Y H:i' }}</p>
        <p>{{ entry.text|linebreaks }}</p>
        <p>
          <a href="{% url 'learning_logs:edit_entry' entry.id %}">
           Edit entry</a>
        </p>
      </li>
    {% empty %}
      <li>There are no entries for this topic yet.</li>
    {% endfor %}

{% endblock content %}`

I’ve reviewed my code against the code in the book, as well as the related github page, to see if maybe there were syntax errors, typos, updated code on his github, etc. and everything looks correct. When i enter the URL in my browser it brings me to the correct page, but the link seems to be adding in all the text, including curly braces, that is referenced. The quotations seem to be properly formatted and matched up. A google search did not proved any seemingly relevant answers, more of what i found seemed to address the problem of getting braces into the output, rather than keeping them from ‘leaking’ into it. I can’t find any real difference between how other links/urls were added to the project and this one. everything else works as expected.

New contributor

chaos_daemon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật