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') }}" 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 中defaultdict()对字典进行初始化的用法介绍
这篇文章主要介绍了python 中defaultdict()对字典进行初始化,一般情况下,在使用字典时,先定义一个空字典(如dict_a = {}),然后往字典中添加元素只需要 dict_a[key] = value即可,本文通过实例代码介绍具体用法,需要的朋友可以参考下2022-07-07python中如何使用xml.dom.minidom模块读取解析xml文件
xml.dom.minidom模块应该是内置模块不用下载安装,本文给大家介绍python中如何使用xml.dom.minidom模块读取解析xml文件,感兴趣的朋友一起看看吧2023-10-10Python中Numpy和Matplotlib的基本使用指南
numpy库处理的最基础数据类型是由同种元素构成的多维数组(ndarray),而matplotlib 是提供数据绘图功能的第三方库,其pyplot子库主要用于实现各种数据展示图形的绘制,这篇文章主要给大家介绍了关于Python中Numpy和Matplotlib的基本使用指南,需要的朋友可以参考下2021-11-11Windows安装Anaconda并且配置国内镜像的详细教程
我们在学习 Python 的时候需要不同的 Python 版本,关系到电脑环境变量配置换来换去很是麻烦,所以这个时候我们需要一个虚拟的 Python 环境变量,这篇文章主要介绍了Windows安装Anaconda并且配置国内镜像教程,需要的朋友可以参考下2023-01-01
最新评论