Home > Blockchain >  NoReverseMatch Django using pk
NoReverseMatch Django using pk

Time:02-12

Reverse for 'update' with keyword arguments '{'pk': ''}' not found. 1 pattern(s) tried: ['basic_app/update/(?P[0-9] )/\Z']

9     <p>Location: {{school_detail.location}} </p>
10    <h3>Students:</h3>
11    {% for student in school_detail.students.all %}
12    <p>{{student.name}} who is {{student.age}} years old</p>
13    {% endfor %}
14  
15  
16  </div>
17  
18  <div >
19  <p><a class='btn btn-warning' href="{% url 'basic_app:update' pk=school_details.pk %}">Update</a></p> 
20  
21  </div>
22  {% endblock %}

Here is urls.py

from django.urls import path
from basic_app import views
app_name='basic_app'

urlpatterns = [
    path('',views.SchoolListView.as_view(),name='list'),
    path('<int:pk>/',views.SchoolDetailView.as_view(),name='detail'),
    path('create/',views.SchoolCreateView.as_view(),name='create'),
    path('update/<int:pk>/',views.SchoolUpdateView.as_view(),name='update'),
    ]

CodePudding user response:

Typo:

{% url 'basic_app:update' pk=school_details.pk %}

Should be:

{% url 'basic_app:update' pk=school_detail.pk %}

CodePudding user response:

Try this:
href="{% url 'update' school_detail.pk %}"
  • Related