我试图在Flask中创建一个基本表单,它将接受输入,操作它,然后返回输出。我遇到了这样一个问题:当我运行终端并试图使我的应用程序在http://127.0.0.1:5000/服务器上工作时,文件不可见。不知道窃听器在哪里?在
我是这样整理我的文件的:
/Users/eas/Desktop/grota/templates//索引.html在
/Users/eas/Desktop/grota/templates//年龄.html在
/Users/eas/桌面/grota/应用程序副本在
这是应用程序副本文件
from flask import Flask, render_template,request
app = Flask(__name__)
@app.route('/send',methods = ['GET','POST'])
def send():
if request.method == 'POST':
age = request.form['age']
return render_template('age.html',age=age)
return render_template('index.html')
if __name__ == '__main__':
app.run()
这是索引.html文件
^{pr2}$这是年龄.html文件
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Your age is{{age}}</h1>
</body>
您没有设置根路径。在
或者你打开http://127.0.0.1:5000/send
或者,您可以使用这个快速而肮脏的修复程序(正如您在decorators中看到的,现在/和/send都被考虑在内):
如果不处理'/'路由,则打开http://127.0.0.1时不会发生任何事情
如果你能更清楚地解释你想要得到什么样的结果,我会帮得更好。在
试试这里:http://127.0.0.1:5000/send
如果这不起作用,你在你的控制台或浏览器中得到了什么错误?在
编辑:
我刚试过,效果很好。请尝试在浏览器的新选项卡中重新加载页面,并查看是否仍会发生。此错误与网页上输入的命名以及使用
request.form['age']
索引表单的方式有关相关问题 更多 >
编程相关推荐