无法处理python Flask redirected()';邮政';方法
基本上,我为我的Flask网页写了两个视图:无法处理python Flask redirected()';邮政';方法,python,html,redirect,post,flask,Python,Html,Redirect,Post,Flask,基本上,我为我的Flask网页写了两个视图: @app.route("/") def main(): 及 稍后,我以类似的方式创建了另外两个视图: @app.route("/questions") def questions(): 及 不知何故,我最后的['POST']方法根本不起作用。谁能告诉我为什么?(在发送第二个['POST']后,出现了“错误请求”。) 这是我的密码: @app.route("/") def main(): questionPath, answersPath,
@app.route("/")
def main():
及
稍后,我以类似的方式创建了另外两个视图:
@app.route("/questions")
def questions():
及
不知何故,我最后的['POST']
方法根本不起作用。谁能告诉我为什么?(在发送第二个['POST']
后,出现了“错误请求”。)
这是我的密码:
@app.route("/")
def main():
questionPath, answersPath, returnPath, databasePath, testName, amount = setup.setup()
names = database.getListOfTests(databasePath)
return render_template('index.html', entries = names)
@app.route('/', methods=['POST'])
def main_post():
text = request.form['text']
processed_text = text
questionPath, answersPath, returnPath, databasePath, testName, amount = setup.setup()
names = database.getListOfTests(databasePath)
if not text in names:
return render_template('index.html', entries = names)
else:
questions2, answers2 = database.getFromDatabase(processed_text,databasePath)
session['messages'] = questions2
return redirect(url_for('questions'))
@app.route("/questions")
def questions():
messages = session['messages']
session['messages'] = messages
return render_template('index2.html', entries = messages)
@app.route('/questions', methods=['POST'])
def questions_post():
text2 = request.form['text2']
processed_text = text2
print(processed_text)
return "XD"
和html:
index.html
<form action="." method="POST">
<input type="text" name="text">
<input type="submit" name="my-form" value="Send">
</form>
index2.html
<form action="." method="POST">
<input type="text" name="text2">
<input type="submit" name="my-form" value="Send2">
</form>
“
不是正确的url
使用空字符串action=“”
或删除action
将表单发送到同一url
“
不是正确的url
<form action="./questions" method="POST">
<input type="text" name="text2">
<input type="submit" name="my-form" value="Send2">
使用空字符串action=”“
或删除action
将表单发送到同一url
<form action="./questions" method="POST">
<input type="text" name="text2">
<input type="submit" name="my-form" value="Send2">
通过编辑index2.htmlaction=“./view”
这将很好地工作。
通过编辑index2.html
action=“./view”
这将很好。下次使用按钮{}
格式化代码。始终显示有问题的完整错误消息。文本错误请求
无效。在调试模式下运行它-app.Run(debug=True)
-以在浏览器中获取更多信息。您确定它提交到了正确的URL吗?通常最好让url\u为
构建url,而不是硬编码。下次使用按钮{}
格式化代码。始终显示有问题的完整错误消息。文本错误请求
无效。在调试模式下运行它-app.Run(debug=True)
-以在浏览器中获取更多信息。您确定它提交到了正确的URL吗?让url\u为构建url而不是硬编码通常是个好主意。非常感谢,伙计!)谢谢你,伙计!;)
<form action="./questions" method="POST">
<input type="text" name="text2">
<input type="submit" name="my-form" value="Send2">