python - Trying to use a access a variable in another scope after render_template() (Flask)? -
i'm trying create web app uses form (wtforms) take 2 svn urls , something/displays them. have update button if clicked only display table info along another submit button function (using show=true
given render_template)
views.py
:
@app.route('/test4', methods=['get','post']) def test4(): form1=svn_path() form2=inputs() if request.method=="post": if request.form.get('updatepaths')=='update' , form1.validate_on_submit(): --> basepath=createdir() svn_url1 = form1.svn_url1.data svn_url2 = form1.svn_url2.data --> prev_pdf=pdf_list(svn_url1,basepath,'prev') #function generates list new_pdf=pdf_list(svn_url2,basepath,'new') #function generates list options=[("none","none")]+[(pdf,pdf) pdf in new_pdf] 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) elif request.form.get('batchfiles')=='submit': #i want use prev_pdf , basepath in part out of scope else: return render_template('test4.html',form1=form1,form2=form2)
the elif
portion : elif request.form.get('batchfiles')=='submit':
second submit appear when first submit clicked, however,
the problem arises when: in section of code want use basepath , prev_pdf out of scope since returned render_template @ end of first if
statement. can't access form1.svn_url1.data anymore either can't recall function.
i can't think of way format code or solution solve problem appreciated.
what you're trying possible if store prev_pdf
somewhere can accessed in next request. suggest either storing list (prev_pdf
) in flask session or storing svn_url1
can regenerate list on second request. see this example of how use flask sessions.
the reason need save data have discovered, each http request self contained , "isolated" previous requests way communicate between requests either pass information want client each time, or save information on server side , access each request.
Comments
Post a Comment