Search code examples
djangodjango-errors

How to deal with a django typeerror some_method() takes exactly 2 arguments (1 given)


I am having a hard time figuring this one out,i keep getting an error:

show_item() takes exactly 2 arguments (1 given)

here are my views:

   def show_item(request,item_slug):
    i = get_object_or_404(Item, slug=item_slug)
    categories = Category.objects.all().prefetch_related('item')
    # need to evaluate the HTTP method
    if request.method == 'POST':
        # add to order..create the bound form
        postdata = request.POST.copy()
        form = ItemAddToCartForm(request,postdata)
        # check validation of posted data
        if form.is_valid():
            # add to order and redirect to order page
            order.add_to_order(request)
            # if test cookie worked, get rid of it
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            url =urlresolvers.reverse('show_order')
            # redirect to order page
            return HttpResponseRedirect(url)
    else:
        # it's a GET, create the unbound from. Note request as a Kwarg
        form = ItemAddToCartForm(request=request,label_suffix=':')
    # assign the hidden input the item slug
    form.fields['item_slug'].widget.attrs['value'] = item_slug
    # set the test cookie on our first GET request
    request.session.set_test_cookie()
    context = {
        'categories':categories,
        'form':form,
    }
    return render_to_response("menu.html",context,context_instance=RequestContext(request))

and here is my url for this view:

url(r'^menu/$','live.views.show_item'),

I have looked around but all in vain, thank you in advance.


Solution

  • item slug needs to be in the url:

    url(r'^menu/(?P<item_slug>[\w-]+)$','live.views.show_item'),