In the 2nd Edition Python Crash Course, Chapter 19 - Letting Users Edit Entries:
I’ve made the coding changes to urls.py and created the edit_entry.html page.
To test the new edit functionality I pull up the page to make edits to the ‘Chess’ topics page:
localhost:8000/edit_entry/1/
The Chess topic has an id of ‘1’.
I make the edits and then click ‘Save changes.’ (Another issue I’m seeing is the ‘Entry:’ label which should not be on this page).
When I go to save the changes (Save changes) I get the Page not found error.
The server seems to be complaining about not finding the Id of the Chess topic, which in this case is ‘1’, I believe. The error message coming back seems to indicate that it’s looking for localhost:8000/edit_entry/10/ as opposed to ‘1’. is that possible? Could it be a ‘browser thing’? I’m using Safari on the MacBook Pro.
That setup for that URL would be in the urls.py file in the /learning_log/learning/logs/ directory. I’ve rechecked the code a dozen times and have even replaced the verision of urls.py with the solution code in the Chapter 19 folder of the exercises I downloaded. So, at this point, I’m using the ‘stock’ code for urls.py.
Below are my screen attachments and code for urls.py.
Any assistance would be appreciated.
-- Vin
urls.py:
"""Defines 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'),
]
The edit_entry.html file:
{% extends "learning_logs/base.html" %}
{% block content %}
<p><a href="{% url 'learning_logs:topic' topic.id %}">{{ topic }}</a></p>
<p>Edit Entry</p>
<form action="% url 'learning_logs:edit_entry' entry.id %}" method='post'>
{% csrf_token %}
{{ form.as_p }}
<button name ="submit">Save changes</button>
</form>
{% endblock content %}

