Reverse for 'update-project' with arguments '('',)' not found. 1 pattern(s) tried: ['update\\-project/(?P<pk>[0-9]+)/\\Z']

Trying to create an update function for a Project Model in Django but i’ve run into a problem. Here’s what i have so far

update view function

@login_required
def updateProject(request, pk):
    project = Project.objects.get(id=pk)
    form = ProjectForm(instance=project)
    
    if request.method == 'POST':
        project.name = request.POST.get('name')
        project.description = request.POST.get('description')
        project.save()
        
        return redirect('project', pk=project.id)
    
    context = {'form': form, 'project': project}
    return render(request, 'projects/project_form.html', context)

This is how I’m calling it in the template

<li><a href="{% url 'update-project' project.id %}">Edit</a></li>

and this is what the urlpattern is

path('update-project/<int:pk>/', views.updateProject, name='update-project'),

What am I missing?

Is there any other view or template (or line in this template) attempting to reverse the update-project url?

Note, it’s generally helpful to post the complete traceback to help ensure we’re looking at the right code.


Traceback (most recent call last):
  File "C:\Users\mikha\issue_env\lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
  File "C:\Users\mikha\issue_env\lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\mikha\mable\projects\views.py", line 31, in project
    return render(request, 'projects/project.html', context)
  File "C:\Users\mikha\issue_env\lib\site-packages\django\shortcuts.py", line 24, in render
    content = loader.render_to_string(template_name, context, request, using=using)
  File "C:\Users\mikha\issue_env\lib\site-packages\django\template\loader.py", line 62, in render_to_string
    return template.render(context, request)
  File "C:\Users\mikha\issue_env\lib\site-packages\django\template\backends\django.py", line 62, in render
    return self.template.render(context)
  File "C:\Users\mikha\issue_env\lib\site-packages\django\template\base.py", line 175, in render
    return self._render(context)
  File "C:\Users\mikha\issue_env\lib\site-packages\django\template\base.py", line 167, in _render
    return self.nodelist.render(context)
  File "C:\Users\mikha\issue_env\lib\site-packages\django\template\base.py", line 1005, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "C:\Users\mikha\issue_env\lib\site-packages\django\template\base.py", line 1005, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "C:\Users\mikha\issue_env\lib\site-packages\django\template\base.py", line 966, in render_annotated
    return self.render(context)
  File "C:\Users\mikha\issue_env\lib\site-packages\django\template\loader_tags.py", line 157, in render
    return compiled_parent._render(context)
  File "C:\Users\mikha\issue_env\lib\site-packages\django\template\base.py", line 167, in _render
    return self.nodelist.render(context)
  File "C:\Users\mikha\issue_env\lib\site-packages\django\template\base.py", line 1005, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "C:\Users\mikha\issue_env\lib\site-packages\django\template\base.py", line 1005, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "C:\Users\mikha\issue_env\lib\site-packages\django\template\base.py", line 966, in render_annotated
    return self.render(context)
  File "C:\Users\mikha\issue_env\lib\site-packages\django\template\loader_tags.py", line 63, in render
    result = block.nodelist.render(context)
  File "C:\Users\mikha\issue_env\lib\site-packages\django\template\base.py", line 1005, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "C:\Users\mikha\issue_env\lib\site-packages\django\template\base.py", line 1005, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "C:\Users\mikha\issue_env\lib\site-packages\django\template\base.py", line 966, in render_annotated
    return self.render(context)
  File "C:\Users\mikha\issue_env\lib\site-packages\django\template\defaulttags.py", line 472, in render
    url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
  File "C:\Users\mikha\issue_env\lib\site-packages\django\urls\base.py", line 88, in reverse
    return resolver._reverse_with_prefix(view, prefix, *args, **kwargs)
  File "C:\Users\mikha\issue_env\lib\site-packages\django\urls\resolvers.py", line 828, in _reverse_with_prefix
    raise NoReverseMatch(msg)

Exception Type: NoReverseMatch at /projects/1/
Exception Value: Reverse for 'update-project' with arguments '('',)' not found. 1 pattern(s) tried: ['update\\-project/(?P<pk>[0-9]+)/\\Z']

Here’s the traceback

What view is being executed for the url /projects/1? That’s the view causing this error.