python - Redirect with data parameter in flask -
i trying learn flask , came across following problem.this example trying implement.
@app.route('/poll', methods = ['get', 'post']) def poll(): form = pollform() if form.validate_on_submit(): return render_template('details.html', form = form) return render_template('poll.html', form=form)
but wanted have different url mapping details.html, purpose created route as,
@app.route('/details/<form>') def details(): return render_template('details.html', form = form):
for using have used
return redirect(url_for('details', form=form))
in poll method inside if condition. , when tried access same detail.html , not able object. when tried replace form string, worked fine. please suggest mechanism access form object inside /details route ?
edit
i asking possible.
@app.route('/poll', methods = ['get', 'post']) def poll(): form = pollform() if form.validate_on_submit(): @app.route('/details') return render_template('details.html', form = form) return render_template('poll.html', form=form)
whenever inside if condition url /poll/details.or there way make kind of url nesting, starting root url child urls gets added depending on business logic.
you cannot put form object url, no. redirect()
response, telling browser go load different url, form object not can cram url path element.
if don't need see different url in browser location bar, don't use redirect call different function:
def details(form): return render_template('details.html', form = form): @app.route('/poll', methods = ['get', 'post']) def poll(): form = pollform() if form.validate_on_submit(): return details(form) return render_template('poll.html', form=form)
if need different url in browser, have <form>
element post /details
route, not /poll
route.
Comments
Post a Comment