0

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'),
]
Ivan Starostin
  • 8,798
  • 5
  • 21
  • 39
Sergei Sokov
  • 46
  • 2
  • 8
  • This could help. https://stackoverflow.com/a/35518016/10357334 – walugembe peter Apr 23 '20 at 18:16
  • `with arguments '('',)'` means that `get_order.id` is evaluating to the empty string `''` in the template. It looks like `{% url 'update_order' order.id %}` might work. – Alasdair Apr 23 '20 at 18:22
  • I think you are rendering the wrong template for the UpdateOrderView, can you share your DetailOrderView code please?. I think that's the one that must render the 'detail_order.html', and not UpdateOrderView – Edgardo Obregón Apr 23 '20 at 19:06

1 Answers1

0

On your template, please put order.id instead of get_order.id. Then your template code will be :

<h2><a href="{% url 'update_order' order.id %}">Update</a></h2>
Muminur Rahman
  • 575
  • 1
  • 8
  • 23
  • If it still doesn't work, then please edit your original question and show the new error. I think you might be getting a different error now, for `reverse_lazy('detail_order')`. It's missing the id, so you need to override `get_success_url` instead. – Alasdair Apr 24 '20 at 16:00