所以我有一个烧瓶应用程序,在主页中我正在呈现一个登录页面以进行登录。登录后,他们会得到一个需要填写的表格。当他们稍后在表单提交过程中登录时,我还会使用用户名值。这是我的相关烧瓶代码:
@app.route('/', methods=['GET', 'POST'])
def home():
return render_template('Login_new.html')
@app.route('/login', methods=['POST'])
def logger():
if request.method == 'POST':
global user
user = request.form['username']
passwrd = request.form['password']
if (user=="admin") and (passwrd=="VendorAdmin2021"):
return redirect(url_for("admin.index"))
url = "api for authentication"
response = requests.post(url, json={"username": user,"password": passwrd}, verify=False)
#data = response.json()
print(response.status_code)
if response.status_code == 200:
return redirect(url_for("test"))
else:
flash('Wrong')
return render_template('Login_new.html')
Run Code Online (Sandbox Code Playgroud)
测试 url 包含实际的表单。这是 Login_new.html 文件:
<html>
<head>
<link rel="stylesheet" href="/static/style2.css">
<title>Sign in</title>
</head>
<body>
<div class="main">
<p class="sign" align="center">Novartis</p>
<form class="form1" action="/login" method="POST" id="myForm"> …Run Code Online (Sandbox Code Playgroud)