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

def updateProject(request, pk):
    project = Project.objects.get(id=pk)
    form = ProjectForm(instance=project)
    if request.method == 'POST': = request.POST.get('name')
        project.description = request.POST.get('description')
        return redirect('project',
    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' %}">Edit</a></li>

and this is what the urlpattern is

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

What am I missing?

Asked By: mdaw11



To redirect to another URL I usually use:

return HttpResponseRedirect(reverse('update-project', args=(,)))

instead of your

return redirect('project',

which probably causes your error after POST

Answered By: Stefano Losi