[英]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.