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


Posted in Python onJune 04, 2020

代码如下

_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>

运行结果

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

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

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

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

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

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

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

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

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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
python实现DNS正向查询、反向查询的例子
Apr 25 Python
使用Python开发windows GUI程序入门实例
Oct 23 Python
Django框架中render_to_response()函数的使用方法
Jul 16 Python
疯狂上涨的Python 开发者应从2.x还是3.x着手?
Nov 16 Python
python 多维切片之冒号和三个点的用法介绍
Apr 19 Python
Python将一个CSV文件里的数据追加到另一个CSV文件的方法
Jul 04 Python
在python中实现调用可执行文件.exe的3种方法
Jul 07 Python
Django 1.10以上版本 url 配置注意事项详解
Aug 05 Python
django 连接数据库 sqlite的例子
Aug 14 Python
pytorch 指定gpu训练与多gpu并行训练示例
Dec 31 Python
使用python实现飞机大战游戏
Mar 23 Python
Python 微信公众号文章爬取的示例代码
Nov 30 Python
python 图像判断,清晰度(明暗),彩色与黑白实例
Jun 04 #Python
完美解决ARIMA模型中plot_acf画不出图的问题
Jun 04 #Python
Python使用Matlab命令过程解析
Jun 04 #Python
Python flask框架端口失效解决方案
Jun 04 #Python
Python实现列表中非负数保留,负数转化为指定的数值方式
Jun 04 #Python
Python新手学习装饰器
Jun 04 #Python
基于python 取余问题(%)详解
Jun 03 #Python
You might like
非洲第一个咖啡超凡杯大赛承办国—卢旺达的咖啡怎么样
2021/03/03 咖啡文化
PHP mkdir()定义和用法
2009/01/14 PHP
php 读取文件乱码问题
2010/02/20 PHP
PHP 数组遍历方法大全(foreach,list,each)
2010/06/30 PHP
WordPress中限制非管理员用户在文章后只能评论一次
2015/12/31 PHP
CodeIgniter整合Smarty的方法详解
2017/08/25 PHP
PHP简单实现循环链表功能示例
2017/11/10 PHP
javascript 混合的构造函数和原型方式,动态原型方式
2009/12/07 Javascript
JS上传图片前的限制包括(jpg jpg gif及大小高宽)等
2012/12/19 Javascript
输入框过滤非数字的js代码
2014/09/18 Javascript
node.js中的http.request.end方法使用说明
2014/12/10 Javascript
jQuery中eq()方法用法实例
2015/01/05 Javascript
vue webpack打包优化操作技巧
2018/02/22 Javascript
详解一次Vue低版本安卓白屏问题的解决过程
2019/05/30 Javascript
[02:12]打造更好的电竞完美世界:完美盛典回顾篇
2018/12/19 DOTA
python中正则表达式的使用详解
2014/10/17 Python
Django应用程序中如何发送电子邮件详解
2017/02/04 Python
Python基于numpy灵活定义神经网络结构的方法
2017/08/19 Python
Python(Django)项目与Apache的管理交互的方法
2018/05/16 Python
python for循环输入一个矩阵的实例
2018/11/14 Python
python3学生名片管理v2.0版
2018/11/29 Python
python+ffmpeg批量去视频开头的方法
2019/01/09 Python
python批量创建指定名称的文件夹
2019/03/21 Python
关于Python中的向量相加和numpy中的向量相加效率对比
2019/08/26 Python
Django集成celery发送异步邮件实例
2019/12/17 Python
PyTorch笔记之scatter()函数的使用
2020/02/12 Python
内容编辑个人求职信
2013/12/10 职场文书
班组长安全工作职责
2014/07/15 职场文书
现场活动策划方案
2014/08/22 职场文书
教师正风肃纪剖析材料
2014/10/20 职场文书
2014年财政局工作总结
2014/12/09 职场文书
文艺晚会开场白
2015/05/29 职场文书
贷款工资证明范本
2015/06/12 职场文书
幼儿教师远程研修感悟
2015/11/18 职场文书
JavaScript 实现页面滚动动画
2021/04/24 Javascript
Java中try catch处理异常示例
2021/12/06 Java/Android