我想将一个在我的程序的路由装饰器中声明的变量导入到表单中,但是表单是在路由中使用的。你知道吗
从我的views.py
函数
@app.route('/test4', methods=['GET','POST'])
def test4():
form1=SVN_Path()
form2=Inputs()
if request.method=="POST" and form1.validate_on_submit():
prev_pdf=["test1.pdf","test2.pdf","test3.pdf","test4.pdf","test5.pdf"]
----> new_pdf=["ex1.pdf","ex2.pdf"]
options=[("None","None")]+[(pdf,pdf) for pdf in new_pdf]
for sub_form in form2.files:
sub_form.choices= options
sub_form.default="None"
return render_template('test4.html',form1=form1,form2=form2,show=True,numfiles=len(prev_pdf),pdflist=prev_pdf)
我想将新的\u pdf的长度导入我的表单文件,该文件与我的文件位于同一目录中视图.py. 我知道我可以使用像lengthpdf=len(new_pdf)
这样的语句获得长度,但是我不确定如何将它导入到包含
class Inputs(Form):
files = FieldList(SelectField(u'File', validators =[Required()]),min_entries = 2)
其中minu条目应等于新pdf的长度
一种解决方案是使用FieldList.append_entry()。因此,与在
files
定义时指定min_entries
不同,您只需附加一个条目(就像您对select字段所做的选择一样)。你知道吗例如
相关问题 更多 >
编程相关推荐