我有一个简单的flask
网络应用。我的 index 模板具有使用javascript和HTML
与客户端进行交互的各种方式。我还有一个 form ,提交后,它会路由到另一个flask进程,并使用request.form
命令来检索用户提交的数据。
但是,我想做些不同的事情。我想在flask
事件上启动javascript
重定向,但要包含一个参数,而不要使用 form 。
例如,我的index.html
文件在模板渲染后将显示以下内容:
function startRedirect(parameter) {
window.location.pathname = '/myRedirect';
}
<input type="checkbox" id="sample" name="sample" onChange="startRedirect(parameter);">
我的flask脚本的一部分将具有:
@app.route('/myRedirect')
def myRedirectFunction():
# do something with the parameter here
return render_template('index.html')
我意识到可以使用 form 来完成此操作,但是我很感兴趣在没有 form 的情况下完成此任务。我正在考虑以某种方式使用request.args
,但不太了解该怎么做。