python的flask框架下实现在浏览器点一个按钮,页面跳到你自定义的其他页面

时间:2020-05-29
本文章向大家介绍python的flask框架下实现在浏览器点一个按钮,页面跳到你自定义的其他页面,主要包括python的flask框架下实现在浏览器点一个按钮,页面跳到你自定义的其他页面使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

_init_.py

from flask import Flask, request, url_for, redirect, render_template

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/cool_form', methods=['GET', 'POST'])
def cool_form():
    if request.method == 'POST':
        # do stuff when the form is submitted

        # redirect to end the POST handling
        # the redirect can be to the same route or somewhere else
        return redirect(url_for('index'))

    # show the form, it wasn't submitted
    return render_template('cool_form.html')

index.html

<!doctype html>
<html>
<body>
    <p><a href="{{ url_for('cool_form') }}">Check out this cool form!</a></p>
</body>
</html>

cool_form.html

<!doctype html>
<html>
<body>
    <form method="post">
        <button type="submit">Do it!</button>
    </form>
</html>

运行结果进入5000端口显示如图,点击这个按钮,跳到自定义的/cool_form页面

 在我的程序里我实现了在web页面点击加法器或者除法器按钮进入相应页面

 详细代码准备上传github

原文地址:https://www.cnblogs.com/qingnvsue/p/12988095.html