Reverse for 'edit_server_request' with arguments '(2,)' not found. 1 pattern(s) tried: ['en/dashboard/edit-server-request/int:pk'] the edit and delete button on the template below raises the error:
<td>
<a class="edit-button" href="{% url 'dashboard:edit_server_request' user.server_user.pk %}">{% trans 'Edit' %}</a>
<a class="delete-button" href="{% url 'dashboard:delete_server_request' user.server_user.pk %}">{% trans 'Delete' %}</a>
</td>
views.py
def edit_server_request(request, pk):
server_request = get_object_or_404(ServerRequest, pk=pk)
if request.method == "POST":
form = ServerRequestForm(request.POST, instance=server_request)
if form.is_valid():
form.save()
return redirect('server_request_list')
else:
form = ServerRequestForm(instance=server_request)
context = {'form': form}
return render(request, 'dashboard/school/edit_server_request.html', context)
def delete_server_request(request, pk):
server_request = get_object_or_404(ServerRequest, pk=pk)
server_request.delete()
return redirect('server_request_list')
urls.py
url(r'edit-server-request/<int:pk>', school_views.edit_server_request, name='edit_server_request'),
url(r'delete-server-request/<int:pk>', school_views.delete_server_request, name='delete_server_request')
edit and delete url raises the error
You are mixing up url
with path
. If you are using Django >=2, than update the urls like this:
path('edit-server-request/<int:pk>', school_views.edit_server_request, name='edit_server_request'),
path('delete-server-request/<int:pk>', school_views.delete_server_request, name='delete_server_request')
Else you need to change the regex inside url()
like this:
url(r'edit-server-request/(?P<pk>[0-9]+)/', school_views.edit_server_request, name='edit_server_request'),
url(r'delete-server-request/(?P<pk>[0-9]+)', school_views.delete_server_request, name='delete_server_request')