Im trying to allow the user to edit an existing entry. But when I include
new_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 %}`
The site throws a NoReverseMatch at /topics/1/ Not too sure where to start looking to solve this issue. Still fairly new to django.
Rest of my code bellow
views.py
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; reate a blank form
form = Entry()
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)
urls.py
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='entry'),
]