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

发布时间:2020-07-18 15:23:08 作者:小猪
来源:亿速云 阅读:1511

这篇文章主要讲解了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>

运行结果

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

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

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

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

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

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

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

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

看完上述内容,是不是对Python中flask框架如何实现浏览器点击自定义跳转页面有进一步的了解,如果还想学习更多内容,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. Python中flask框架端口失效怎么办
  2. 详解Python中Flask框架如何实现简单加法工具

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

python flask

上一篇:怎样设置PL/SQL的日期显示格式

下一篇:JavaScript冒泡算法原理与实现方法的详细解析

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》