提交到flask服务器后重定向到html页面

提交到flask服务器后重定向到html页面,html,flask,rendering,Html,Flask,Rendering,我不熟悉flask、html和java脚本。 我有一个index.html页面,可以呈现到另一个html表单页面。 我的问题是:当我单击提交按钮时,我想返回index.html。 我找不到满足我需要的信息。 现在我有了这样的东西: <form action="http://127.0.0.1:5000/api/addClient" method="POST"> <button type="sub

我不熟悉flask、html和java脚本。 我有一个index.html页面,可以呈现到另一个html表单页面。 我的问题是:当我单击提交按钮时,我想返回index.html。 我找不到满足我需要的信息。 现在我有了这样的东西:

<form action="http://127.0.0.1:5000/api/addClient" method="POST"> 
                <button type="submit"  class="btn btn-primary">Submit</button>
        
</form>
但当我这样做时,我会: 我可以看到json数据,而不是我的网页


我很乐意提供任何帮助

您得到的是JSON,因为当您转到
('/api/addClient')
路径时,它会将您重定向到索引函数,该函数最终返回变量
ret
,即屏幕上显示的JSON


在索引函数中,将最后一个石灰更改为
render\u template(“index.html”)
。在同一行中,如果希望在HTML文件中使用ret变量,请将其改为
render\u template(“index.HTML”,ret=ret)

谢谢您的回复。我已经用JS方法解决了我的问题。不那么优雅,但对我有用。

@app.route('/api/debt')
def index():
    file = get_resent_file()
    debt_df = get_df(file)
    debt_json = debt_df.to_json(orient='records', force_ascii=False)
    ret = jsonify(json.loads(debt_json))
    return ret


@app.route('/api/addClient', methods=['GET', 'POST'])
def addClient():
    #things I do with data from submitted form...
    return redirect(url_for('index'))