Django: Reverse for '*' with arguments '()' and keyword arguments '{a,b}' not found. 1 pattern(s) tried: ['order/pay/(?P<pk>\\d+)/$'] -
i have views. 1 triggers overview of guest's orders. , 1 sets order paid , should go overview:
@login_required def guest_detail(request, pk): guest = get_object_or_404(guest, pk=pk) open_orders = order.objects.filter(guest = guest, is_paid=false) paid_orders = order.objects.filter(guest = guest, is_paid=true) if request.method == "post": form = registerguestform(request.post, instance=guest) if form.is_valid(): guest = form.save(commit=false) guest.save() #post.published_date = timezone.now() return redirect('guest_detail', pk=guest.pk) else: form = registerguestform(instance=guest) context = {'form': form} context['open_orders'] = open_orders context['paid_orders'] = paid_orders return render(request, 'hotel/guest_detail.html', context)
this view rendered template:
<div class="col-md-8 col-xs-12"> <h3>guest information:</h3> <form method="post" class="post-form">{% csrf_token %} {{ form.as_p }} <button type="submit" class="save-guest btn btn-default">save</button> </form> <h3>open orders:</h3> <table class="table table-condensed table-guest-order"> <tr> <th>date</th> <th>amount</th> <th>item</th> <th>price</th> <th><th> </tr> {% order in open_orders %} <tr> <td>{{ order.date }}</td> <td>{{ order.amount }}</td> <td>{{ order.item }}</td> <td>{{ order.price }}</td> <td><a href="{% url 'pay_order' pk=order.pk order_guest=order.guest.pk %}">pay</a></td> </tr> {% endfor %} </table> </div>
the pay_order link calls following view, should redirect me back, come from:
@login_required def pay_order(request, *args, **kwargs): order = order.objects.get(pk=kwargs['pk']) if order.is_paid false: order.is_paid = true order.paid_date = timezone.now() order.save() return redirect(views.guest_detail, pk=kwargs['order_guest'])
but receive error
reverse 'pay_order' arguments '()' , keyword arguments '{'order_guest': 10, 'pk': 19}' not found. 1 pattern(s) tried: ['order/pay/(?p\d+)/$']
this urls.py used:
from django.conf.urls import url . import views urlpatterns = [ url(r'^$', views.home, name='home'), url(r'^rooms/$', views.listroomsview.as_view(), name='rooms'), url(r'^service/$', views.service, name='service'), url(r'^contact/$', views.contact, name='contact'), url(r'^about/$', views.about, name='about'), url(r'^guests/$', views.listguestsview.as_view(), name='guests'), url(r'^guests/edit/(?p<pk>\d+)/$', views.guest_detail, name='guest_detail'), url(r'^register_guest/$', views.register_guest, name='register_guest'), url(r'^order/edit/(?p<pk>\d+)/$', views.order_detail, name='order'), url(r'^order/$', views.register_order, name='new_order'), url(r'^order/list/$', views.listordersview.as_view(), name='open_orders'), url(r'^order/pay/(?p<pk>\d+)/$', views.pay_order, name='pay_order'), ]
when call guest_detail view guest has open payments. if guest has no open payments works fine. presume problem way try pass pk of guest pay_order view.
you're trying pass parameter "order_guest" pay_order
view, url not expecting parameter, , neither view using it. shouldn't pass @ all; take out of values in {% url %}
tag.
<a href="{% url 'pay_order' pk=order.pk %}">pay</a>
Comments
Post a Comment