Django error NoReverseMatch: Reverse for ‘student_update’ with arguments ‘(”,)’ not found. 1 pattern(s) tried: [‘students/(?P<pk>\\d+)/update/$’]

By | August 11, 2018

Cant quite figure this one out, full error is:

NoReverseMatch: Reverse for 'student_update' with arguments '('',)' not found. 1 pattern(s) tried: ['students/(?P\d+)/update/$']*

models.py

class Student(models.Model):
    student_id = models.CharField(max_length=10, primary_key=True)
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)

class Meta:
    verbose_name = "Student"
    verbose_name_plural = "Students"

urls.py

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', HomeView.as_view()),
    url(r'^students/$', views.students, name='students'),
    url(r'courses/$', views.courses, name='courses'),
    url(r'registrations/$', views.registrations, name='registrations'),
    url(r'thanks/', views.thanks, name='thanks'),
    url(r'students/create/', views.student_create, name='student_create'),
    url(r'^students/(?P<pk>\d+)/update/$', views.student_update, 
      name='student_update'),

html file

% for student in students %}
 <tr>
 <td>{{ student.name }}</td>
 <td>{{ student.id }}</td>
 <td>
   <button type="button"
          class="btn btn-warning btn-sm js-update-student"
          data-url="{% url 'student_update' student.id %}">
    <span class="glyphicon glyphicon-pencil"></span> Edit
  </button>
</td>
</tr>
{% empty %}
 <tr>
  <td colspan="7" class="text-center bg-warning">No student</td>
 </tr>
{% endfor %}