我想在网页上同时显示form1
和form2
。如果form2
已填满(if success == True
),我希望我的观看不执行if form1.is_valid:
(这会产生错误)。如何在views.py?{/ p>中访问success
的值
forms.py
class Form1(forms.Form):
....
....
def clean(self):
....
....
class Form2(forms.Form):
....
....
def clean(self):
....
success = False
views.py
def my_view(request, element_pk):
....
....
if request.method == POST:
form2 = Form2(request.POST)
form1 = Form1(request.POST)
if form2.is_valid():
....
if form1.is_valid():
....
else:
form2 = Form2()
form1 = Form1()
答案 0 :(得分:0)
对于您的var
FExecution: IdwsProgramExecution;
UnitSymbol: TUnitMainSymbol;
FuncSymbol: TFuncSymbol;
Info: IInfo;
begin
...
UnitSymbol := FExecution.Prog.UnitMains.Find('Test');
FuncSymbol := UnitSymbol.Table.FindSymbol('ClickProc', cvPublic) as TFuncSymbol; // Returns nil :-(
Info := FExecution.Info.FuncBySym[FuncSymbol];
Info.Call;
...
或<input />
标记,请为每个表单使用<button></button>
参数(即。):
name
然后,在您看来,执行以下操作:
<button type="submit" name="form_1">Go!</button>
答案 1 :(得分:0)
正如您在clean方法中所做的那样设置success = False
仅在本地设置它。将值存储在类(self.success = False
)或cleaning_data(self.cleaned_data['success'] = False
中,假设您的表单没有名为success的字段。)
然后,您可以使用以下命令访问该值:
if form2.is_valid():
success = form2.success
或
if form2.is_valid():
success = form2.cleaned_data.get('success')
有关clean
功能的详细信息,请参阅docs。