我在我的Django项目中写了一个as_view(),其中给出了两个位置参数来提交表单。渲染模板时会引发类型错误:as_view()占用1个位置参数,但给出了2个。我很感激帮助我解决这个问题。
Views.py:
class AuctionView(LoginRequiredMixin, MultipleFormsView):
template_name = 'loggedin_load/active_deals.html'
form_classes = {'accept_bid': AuctionForm,
'accepted': AcceptedForm}
success_url = '/live_bids/'
@method_decorator(user_passes_test(not_in_company_group, login_url='/login/'))
def dispatch(self, *args, **kwargs):
return super(AuctionView, self).dispatch(*args, **kwargs)
def accept_bid_form_valid(self, request, post_id, bid_id, form):
accept_bid = form.save(commit=False)
accept_bid.bid = bid
accept_bid.post = post
accept_bid.post_owner = request.user
accept_bid.save()
form.save()
return form.accept_bid(self.request, redirect_url=self.get_success_url())
def accepted_form_valid(self, form):
accepted = form1.save(commit=False)
return form.accepted(self.request, user, self.get_success_url())
urls.py:
url(r'^post/(?P<post_id>[\w-]+)/bid/(?P<bid_id>[\w-]+)/$', AuctionView.as_view, name='accept_bid'),
答案 0 :(得分:3)
url(r'^post/(?P<post_id>[\w-]+)/bid/(?P<bid_id>[\w-]+)/$', AuctionView.as_view(), name='accept_bid'),