Reputation: 455
i have two views,
def create_order(request,id):
orders = Order()
orders.restaurant = Restaurant.objects.get(pk=id)
orders.save()
if orders.pk:
....
return orders
the second view calls the first one,
def show_checkout(request,id):
if order.is_empty(request):
...
if request.method == 'POST':
restaurant = Restaurant.objects.get(pk=id)
form = forms.CheckoutForm(request.POST,instance=restaurant)
if form.is_valid():
order_created = create_order(request,restaurant)
.......
return render_to_response('checkout/checkout.html',context,context_instance=RequestContext(request))
i when i run this i get error `
show_checkout() takes exactly 2 arguments (1 given)` My Traceback,
Traceback:
File "/home/matsinvasion/projects/f4l/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
Exception Type: TypeError at /orders/checkout/
Exception Value: show_checkout() takes exactly 2 arguments (1 given)
i go about this and suggesting a good read on dealing with arguments is appreciated
from .views import show_item, show_order,get_category,homepage,show_checkout,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/$',show_order,name="order_index"),
url(r'^item/(?P<id>\w+)/$',show_item, name="item_order"),
url(r'^checkout/$',show_checkout,name="checkout"),
url(r'^reciept/$',reciept,name="checkout_reciept"),
)
fixing urls.py, raises NoReverseMatch error
in this function,
Reverse for 'checkout' with arguments '()' and keyword arguments '{}' not found.
def get_checkout_url(request):
return urlresolvers.reverse('checkout')
Upvotes: 0
Views: 1469
Reputation: 6320
Your show_checkout
view is taking a second id
parameter that you are not accounting for in your URLs.
You need to add it to your URL as follows:
url(r'^checkout/(?P<checkout_id>[\w|\W]+)$',show_checkout,name="checkout"),
And when you call the URL in your template, you need to pass the id
that you are asking for in the view like so:
{% url checkout checkout.id %}
Or if you are using Django 1.5:
{% url 'checkout' checkout.id %}
Upvotes: 1