我有一个功能,
def show_checkout(request,id):
if order.is_empty(request):
cart_url = urlresolvers.reverse('order_index')
return HttpResponseRedirect(cart_url)
if request.method == 'POST':
resto = Restaurant.objects.get(pk=id)
form = forms.CheckoutForm(request.POST,instance=restaurant)
if form.is_valid():
order_created = create_order(request,resto)
.....
return render(request,'checkout/checkout.html',context)
在下一个视图中,我尝试提交表单,
def show_order(request):
if request.method == 'POST':
postdata = request.POST.copy()
if postdata['submit'] == 'checkout':
checkout_url = checkout.get_checkout_url(request)
return HttpResponseRedirect(checkout_url)
上面的视图在 checkout.py 中调用了这个视图
def get_checkout_url(request):
return urlresolvers.reverse('checkout')
urls.py
url(r'^checkout/(?P<id>\w+)$',show_checkout,name="checkout"),
毕竟我得到了错误,
Reverse for 'checkout' with arguments '()' and keyword arguments '{}' not found.
我以为我在正确的轨道上,我想我不是。
在show_order
我做的编辑
def show_order(request,id):
resto = Restaurant.objects.get(pk=id)
...
if postdata['submit'] == 'checkout':
# checkout_url = checkout.get_checkout_url(request)
return HttpResponseRedirect(urlresolvers.reverse('checkout',kwargs={'id':resto}))
在网址中我确实url(r'^your_order/(?P<id>\w+)$',show_order,name="order_index"),
会引发错误page not found
完整的 urls.py
from .views import show_item,show_checkout,show_order,get_category,homepage,reciept
from f4l import settings
from django.conf.urls.defaults import patterns, include, url
urlpatterns = patterns('',
url(r'^$',homepage,name="homepage"),
url(r'^menu/(\d+)$',get_category, name="f4l_menu"),
url(r'^your_order/(?P<id>\w+)$',show_order,name="order_index"),
url(r'^item/(?P<id>\w+)/$',show_item, name="item_order"),
url(r'^checkout/(?P<id>\w+)$',show_checkout,name="checkout"),
url(r'^reciept/$',reciept,name="checkout_reciept"),