使用烧瓶重定向到其他HTML文件

发布于 2025-02-05 18:20:20 字数 395 浏览 3 评论 0原文

我有2个HTML文件,一个我在开始时使用的一个文件,我想要的是,在用户单击按钮和发布请求中后,它应该更改为另一个HTML页面。

我当前的代码(一部分):

...

@app.route('/test', methods=['POST'])                                
def test():
    output = request.get_json()
    print(output)
    render_template('secondform.html', static_folder='static')

...

但问题是这是行不通的……

我将如何使它在检测到发布请求后,它将切换到全新的HTML页面。

任何帮助都赞赏。

I have 2 HTML files, one I am using in the beginning, and what I want is that after the user clicks a button and a POST request comes into the code, it should change to another HTML page.

My current code (part of it):

...

@app.route('/test', methods=['POST'])                                
def test():
    output = request.get_json()
    print(output)
    render_template('secondform.html', static_folder='static')

...

But the problem is that this doesn't work...

How would I make it that it would that after a POST request has been detected, it would switch to a completely new HTML page.

Any help appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱娆 2025-02-12 18:20:20

要实现此目标,只需检查 request.method 相应地,get发布

from flask import request
@app.route('/test', methods=["POST", "GET"])                                
def test():
    if request.method == "POST"
        output = request.get_json()
        print(output)
        return render_template('secondform.html', static_folder='static')
    return render_template('<get_request_template_file>.html', static_folder='static') 
    #above will be executed on GET request and will render <get_request_template_file>.html 

To achieve this simply check the request.method and add logic accordingly for GET and POST :

from flask import request
@app.route('/test', methods=["POST", "GET"])                                
def test():
    if request.method == "POST"
        output = request.get_json()
        print(output)
        return render_template('secondform.html', static_folder='static')
    return render_template('<get_request_template_file>.html', static_folder='static') 
    #above will be executed on GET request and will render <get_request_template_file>.html 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文