问题描述
我能够使用 Flask 将数据从一个 html 表单传递到第二个 html 页面。但是当我尝试将数据从第二个 html 页面传递到第三个 html 页面时,出现错误:
werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: 浏览器(或代理)发送了一个该服务器无法理解的请求。 KeyError: '二进制'
我基本上是尝试在第一个html页面上输入二进制数,在第二个html页面上将其转换为十进制数,然后在第三个页面上将其转换为十六进制数。这是我的烧瓶代码:
</div>
<button type="submit" class="btn btn-success btn-flat m-b-30 m-t-30">Sign in</button>
<div class="social-login-content">
<div class="social-button">
<button type="button" class="btn social facebook btn-flat btn-addon mb-3"><i class="ti-facebook"></i>Sign in with facebook</button>
<button type="button" class="btn social twitter btn-flat btn-addon mt-2"><i class="ti-twitter"></i>Sign in with twitter</button>
</div>
</div>
<div class="register-link m-t-15 text-center">
<p>Don't have account ? <a href="#"> Sign Up Here</a></p>
</div>
</form>
当我再次单击第二页上的提交时,它似乎试图从 from flask import Flask,redirect,url_for,render_template,request
app = Flask(__name__)
@app.route('/',methods=['POST','GET'])
def input_binary():
if request.method == "POST":
binary = request.form["binary"]
return redirect(url_for("show_decimal",bin=binary))
else:
return render_template("binary.html")
@app.route('/<bin>','GET'])
def show_decimal(bin):
if request.method == "POST":
decimal = request.form["decimal"]
return redirect(url_for("show_hex",dec = decimal))
else:
decimal = int(bin,2)
return render_template("decimal.html",dec=decimal)
@app.route('/<dec>','GET'])
def show_hex(dec):
hexadecimal_string = hex(int(dec))
return render_template("hex.html",hex = hexadecimal_string)
if __name__ == "__main__":
app.run(debug=True)
函数而不是 def input_binary
函数运行代码。可能跟第二页的提交按钮有关?
这是第二个html页面上的html:
def show_hex
有什么建议吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)