Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法处理python Flask redirected()';邮政';方法_Python_Html_Redirect_Post_Flask - Fatal编程技术网

无法处理python Flask redirected()';邮政';方法

无法处理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,

基本上,我为我的Flask网页写了两个视图:

@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.html
action=“./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">