首页 > python web

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

时间:2020-06-25 python web 查看: 1587

代码如下

_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博客。

展开全文
上一篇:Python flask框架端口失效解决方案
下一篇:Python flask框架实现查询数据库并显示数据
输入字:
相关知识
django学习之ajax post传参的2种格式实例

AJAX除了异步的特点外,还有一个就是:浏览器页面局部刷新,下面这篇文章主要给大家介绍了关于django学习之ajax post传参的2种格式的相关资料,需要的朋友可以参考下

Python djanjo之csrf防跨站攻击实验过程

csrf攻击,即cross site request forgery跨站(域名)请求伪造,这里的forgery就是伪造的意思。这篇文章主要给大家介绍了关于Python djanjo之csrf防跨站攻击的相关资料,需要的朋友可以参考下

django admin实现动态多选框表单的示例代码

借助django-admin,可以快速得到CRUD界面,但若需要创建多选标签字段时,需要对表单进行调整,本文通过示例代码给大家介绍django admin多选框表单的实现方法,感兴趣的朋友跟随小编一起看看吧

Flask登录注册项目的简单实现

一个简单的用户注册和登录的页面,涉及到验证,数据库存储等等,本文主要介绍了Flask登录注册项目的简单实现,从目录结构开始,感兴趣的可以了解一下