-1

I have a form at /item/3/sell_offer/4/
with action="add_post/"

I expect it go to /item/3/sell_offer/4/add_post

The relevant urlpatterns are

(r'^item/(?P<item_id>\d+)/sell_offer/(?P<sell_offer_id>\d+)/$', views.sell_offer_page),
(r'^item/(?P<item_id>\d+)/sell_offer/(?P<sell_offer_id>\d+)/add_post/$', views.sell_offer_add_post),

and the view looks like..

def sell_offer_add_post(request, item_id, sell_offer_id):
    p = request.POST

    if p.has_key("body") and p["body"]:
        post = SellOfferPost(sell_offer=SellOfferPost.objects.get(pk=sell_offer_id))
        form = SellOfferPostForm(p, instance=post)
        post = form.save()
        post.save()

    return HttpResponseRedirect(reverse('views.sell_offer_page', args=[item_id, sell_offer_id]))

I think post action doesn't actually find it's way to the view.
Below is the error message

Request Method: POST
Request URL:    http://......:8000/item/1/sell_offer/4/add_post/
Django Version: 1.3.1
Exception Type: TypeError
Exception Value:    
sell_offer_add_post() got an unexpected keyword argument 'item_id'
Exception Location: /usr/local/lib/python2.6/dist-packages/Django-1.3.1-py2.6.egg/django/core/handlers/base.py in get_response, line 111

What am I doing wrong here?

4

2 回答 2

0

确保您没有调用其他视图sell_offer_add_post()

于 2012-04-28T05:12:10.367 回答
0

尝试将您的视图签名设置为:

def sell_offer_add_post(request, item_id=None, sell_offer_id=None):

我还没有测试过,但如果我没记错的话,当您在 URL 中使用命名捕获组时,我认为 django 会尝试传递命名关键字。您需要检查视图中的值。

于 2012-04-28T16:18:29.570 回答