NoReverseMatch at /update-orders/12 Reverse for 'update_order' with arguments '('',)' not found. 1 pattern(s) tried: ['update\\-orders/(?P<pk>[0-9]+)$']

51 views
Skip to first unread message

Sergei Sokov

unread,
Apr 23, 2020, 2:30:18 PM4/23/20
to Django users
Hello everybody

I have a problem:

NoReverseMatch at /update-orders/12

Reverse for 'update_order' with arguments '('',)' not found. 1 pattern(s) tried: ['update\\-orders/(?P<pk>[0-9]+)$']
Request Method:GET
Request URL:http://192.168.0.249:8000/update-orders/12
Django Version:3.0.5
Exception Type:NoReverseMatch
Exception Value:
Reverse for 'update_order' with arguments '('',)' not found. 1 pattern(s) tried: ['update\\-orders/(?P<pk>[0-9]+)$']
Exception Location:/root/.local/share/virtualenvs/myp4-4l8n6HJk/lib/python3.7/site-packages/django/urls/resolvers.py in _reverse_with_prefix, line 677
Python Executable:/root/.local/share/virtualenvs/myp4-4l8n6HJk/bin/python
Python Version:3.7.3
Python Path:
['/var/workspace/myp4/webprint',
 '/usr/lib/python37.zip',
 '/usr/lib/python3.7',
 '/usr/lib/python3.7/lib-dynload',
 '/root/.local/share/virtualenvs/myp4-4l8n6HJk/lib/python3.7/site-packages']

Why do I have this Error during template rendering?

detail_order.html
{% extends 'index.html' %}

{% block content %}
<p><a href="{% url 'orders' %}">Back</a></p>
<h1>Заказ {{get_order.number_order}}</h1>
<h2><a href="{% url 'update_order' get_order.id %}">Update</a></h2>

views.py
class UpdateOrderView(CustomSuccessMessageMixin, UpdateView):
    model = Order
    template_name = 'detail_order.html'
    form_class = OrderForm
    success_url = reverse_lazy('detail_order')
    success_msg = 'Ok'
    def get_context_data(self, **kwargs):
        kwargs['update'] = True
        return super().get_context_data(**kwargs)

urls.py
from django.contrib import admin
from django.urls import path, include
from .views import *
from print import views

urlpatterns = [
    path('', views.home_page, name='index'),
    path('orders', views.OrderCreateView.as_view(), name='orders'),
    path('update-orders/<int:pk>', views.UpdateOrderView.as_view(), name='update_order'), # THIS PATH
    path('delete-orders/<int:pk>', views.DeleteOrderView.as_view(), name='delete_order'),
    path('detail-order/<int:pk>', views.DetailOrderView.as_view(), name='detail_order'),
    path('login', views.MyprojectLoginView.as_view(), name='login_page'),
    path('register', views.RegisterUserView.as_view(), name='register_page'),
    path('logout', views.MyprojectLogout.as_view(), name='logout_page'),
]



Anonymous Patel

unread,
Apr 23, 2020, 2:52:14 PM4/23/20
to django...@googlegroups.com
Hey sergei.
Here is group know as errormania. This is group of Developers who are solving this errors we developer's are facing.

And here is the. Link which can help you so take a look and let them know you liked this channel.
If you like it they have telegram channel 
@errormania you can join that as well

Raj Patel

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ed4df72d-838e-4e53-b79e-78eda6902195%40googlegroups.com.

Raja Sekar Sambath

unread,
Apr 24, 2020, 3:42:51 AM4/24/20
to django...@googlegroups.com
path('detail-order/<int:pk>', views.DetailOrderView.as_view(), name='detail_order'),  

detail_order required primarykey to be passed to display the order.


success_url = reverse_lazy('detail_order')  

Primary key is missing here


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ed4df72d-838e-4e53-b79e-78eda6902195%40googlegroups.com.


--
Thanks & Regards,

Raja Sekar Sampath
Reply all
Reply to author
Forward
0 new messages