Python 变量,用于获取TemplateView的\u context\u data()方法
在第页bills.html上,我有一张表格(action-order\u page.html) 在页面order\u page.html我有表单,其中一个字段必须具有来自bills.html`s表单的值 视图。py:Python 变量,用于获取TemplateView的\u context\u data()方法,python,django,Python,Django,在第页bills.html上,我有一张表格(action-order\u page.html) 在页面order\u page.html我有表单,其中一个字段必须具有来自bills.html`s表单的值 视图。py: class OrderPage(TemplateView): template_name = 'order_page.html' form_class = BillAmount def post(self, request, *args, **kwargs
class OrderPage(TemplateView):
template_name = 'order_page.html'
form_class = BillAmount
def post(self, request, *args, **kwargs):
context = self.get_context_data()
form = self.form_class(request.POST)
if form.is_valid():
amount = form.cleaned_data['sum'] # this value I need in get_context_data()
return super(OrderPage, self).render_to_response(context)
def get_context_data(self, **kwargs):
amount = 2314 # here I need value from post()
ctx = super(OrderPage, self).get_context_data(**kwargs)
ctx['form'] = FinishPaymentForm(instance=payment) # another form
return ctx
我不知道该怎么做。我尝试了post():OrderPage.amount=N
和许多其他变体,但它们不起作用
如何做到这一点
谢谢 试试这个:
class OrderPage(TemplateView):
...
amount = None
def post(self, request, *args, **kwargs):
...
if form.is_valid():
self.amount = form.cleaned_data['sum']
...
def get_context_data(self, **kwargs):
# Here you can use self.amount
...