这是我的Flask代码,它应该打开另一个页面,欢迎从我的html代码登录的用户
from flask import Flask, redirect, url_for, request,render_template
app = Flask(__name__)
@app.route('/')
def home():
return render_template('login.html')
@app.route('/success/<name>')
def success(name):
return ('Welcome %s' % name)
@app.route('/login', methods = ['POST','GET'])
def login():
if request.method == 'POST':
user = request.form['nm']
return (redirect(url_for(' success' , name = user)))
else:
user = request.args.get('nm')
return (redirect(url_for('success', name = user)))
if __name__ == '__main__':
app. run(debug = True)
这是我的html代码
<html>
<body>
<form action="http://localhost:5000/login" method="post" >
<p>Enter Name: </p>
<p><input type = "text" name = "nm"/></p>
<p><input type = "submit" value="submit" /></p>
</form>
</body>
</html>
html代码在终端中给出了此错误
错误:Get_Updates_Processor.cc(258)]在GetUpdates期间PostClientToServerMessage()失败,错误为%2
少数错误:
success
中有一个额外的空格。__main__
未正确对齐。这是固定代码
from flask import Flask, redirect, url_for, request,render_template
app = Flask(__name__)
@app.route('/')
def home():
return render_template('login.html')
@app.route('/success/<name>')
def success(name):
return ('Welcome %s' % name)
@app.route('/login', methods = ['POST','GET'])
def login():
if request.method == 'POST':
user = request.form['nm']
return (redirect(url_for('success' , name = user)))
else:
user = request.args.get('nm')
return (redirect(url_for('success', name = user)))
if __name__ == '__main__':
app. run(debug = True)