前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python flask框架实现浏览器点击自定义跳转页面

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

作者头像
砸漏
发布2020-10-29 17:15:46
4.7K0
发布2020-10-29 17:15:46
举报
文章被收录于专栏:恩蓝脚本

代码如下

_init_.py

代码语言:javascript
复制
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

代码语言:javascript
复制
<!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

代码语言:javascript
复制
<!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文件夹

以上就是本文的全部内容,希望对大家的学习有所帮助。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-09-11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档