在我的django项目中,我需要创建表单(input_optimization_problem
),用户将指定有多少边界有优化问题。然后我需要将此信息传递给下一个表单(optimization_problem2
),其中用户可以输入方程本身,指定最大化或最小化和界限(我们从表单1获得的边界的字段数)。
现在我的代码在views.py
:
from WebCalcApp.optimize import optimize
from .forms import *
def input_optimization_problem(request):
title = 'Bounds'
form = InputOptimizationLimitations(request.POST or None)
context = {'title' : title,
'form' : form,
}
if form.is_valid():
bounds_num = form.cleaned_data['bounds_num']
return optimization_problem2(request, bounds_num)
else:
form = InputOptimizationLimitations()
return render(request, 'in.html', context)
def optimization_problem2(request, bounds_num):
title = 'equation'
form = InputOptimizationProblem(request.POST or None) #, bounds_num)
context = {'title' : title,
'form' : form,
}
if form.is_valid():
formula = form.cleaned_data['formula']
min_max = form.cleaned_data['min_max']
# bounds = form.cleaned_data['bounds']
res_dict = optimize(formula, min_max) #, bounds)
loop = range(0,len(res_dict)-1)
context = {'res' : res_dict,
'loop' : loop,
'formula' : formula,
# 'bounds' : bounds
}
return render(request, 'out.html', context)
return render(request, 'in.html', context)
结果是,在填写表单input_optimization_problem
后,它会呈现下一个表单optimization_problem2
,但之后会返回input_optimization_problem
而不是使用优化结果呈现out.html
可能我应该以不同的方式做到这一点然后我尝试但我试图谷歌并没有找到一些有用的信息。