python的flask框架怎么跳转到别的页面_Python flask框架实现浏览器点击自定义跳转页面...

代码如下

_init_.pyfrom 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

Check out this cool form!

cool_form.html

Do it!

运行结果

671c50f7114d64b2994b44a72eb4742b.gif

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

671c50f7114d64b2994b44a72eb4742b.gif

代码在github:https://github.com/qingnvsue/flask中的webbutton文件夹

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

671c50f7114d64b2994b44a72eb4742b.gif

671c50f7114d64b2994b44a72eb4742b.gif

671c50f7114d64b2994b44a72eb4742b.gif

代码在github:https://github.com/qingnvsue/flask中的add文件夹

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持爱安网。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值