Python flask框架实现浏览器点击自定义跳转页面

Jenny ·
更新时间:2024-09-21
· 756 次阅读

代码如下

_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') }}" rel="external nofollow" >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页面

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

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

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

您可能感兴趣的文章:Python flask框架端口失效解决方案Python flask框架如何显示图像到web页面python2.7的flask框架之引用js&css等静态文件的实现方法python flask框架实现传数据到js的方法分析Python2.7环境Flask框架安装简明教程【已测试】Python使用flask框架操作sqlite3的两种方式使用Python的Flask框架表单插件Flask-WTF实现Web登录验证



跳转页面 浏览器 自定义 flask Python

需要 登录 后方可回复, 如果你还没有账号请 注册新账号