[英]calling a variable from one app to another in flask
我在烧瓶中有以下应用程序,其中一个将收到用户的输入。
/vrf_extension 应用程序将呈现用户输入值的 html 文件。 之后我想获取该变量并在 /vrf_ext_config 应用程序中使用它。 我已经尝试了以下带有session
代码,但它没有将它传递给 /vrf_ext_config。 你知道我可以通过任何其他方式实现这一目标吗?
--- app.py ---
@app.route('/vrf_ext_config', methods=["POST", "GET"])
def vrf_ext_config():
if request.method == "POST":
sa_name = session.get('sa_name')
print(sa_name)
return render_template("vrf_ext_config.html")
@app.route('/vrf_extension', methods=["POST", "GET"])
def vrf_extension():
if request.method == "POST":
session['sa_name'] = request.form["sa_name"]
return render_template("vrf_ext_config.html")
return render_template("vrf_extension.html")
---- vrf_extension.html ----
<title>VRF Extenstion</title>
{% extends 'base.html' %}
{% block content %}
<html>
<head>
</head>
<body>
<p><h3>Please Choose the Access Switch you would like to extend the VRF to: </h3>
<form method="post" action="/vrf_extension">
<p> Please enter Access Switch name: <input name="sa_name"/></p>
<p><input type="submit" value="Go to Config Generator" /></p>
</form>
</body>
</html>
{% endblock %}
请更换
<form method="post" action="/vrf_extension">
到
<form method="post" action="/vrf_ext_config">
在 HTML 中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.