当前位置:网站首页>flask框架中页面跳转与重定向
flask框架中页面跳转与重定向
2022-07-24 03:51:00 【IT之一小佬】
示例代码1:
from flask import Flask, redirect, url_for
app = Flask(__name__)
@app.route('/')
def index():
login_url = url_for('login')
return redirect(login_url)
@app.route('/login')
def login():
return '这是登陆页面'
if __name__ == '__main__':
app.run(debug=True)

示例代码2:
from flask import Flask, request, redirect, url_for
app = Flask(__name__)
@app.route('/')
def login():
return 'login'
@app.route('/profile/')
def profile():
name = request.args.get('name')
if not name:
return redirect('http://www.baidu.com') # 注意:如果这儿直接写www.baidu.com是不能实现重定向的,是url的拼接
else:
return redirect(url_for('login'))
if __name__ == '__main__':
app.run(debug=True)

边栏推荐
- Pat grade a 1041 be unique
- Convert the pseudo array returned by childNodes into a true array
- Pat class a 1040 long symmetric string
- IO stream sorting
- MySQL cannot be accessed. Navicat prompt: is not allowed to connect to this MySQL server
- What is the product and expressiveness of 113700 Xingrui? Come and have a look
- 会话技术相关
- Two stroke engine mean value model simulation
- Shengsi YiDianTong | deep learning analysis of classical convolutional neural network
- Mitsubishi Ethernet module Yuanchuang intelligent control yc8000-fx connection MCGS operation method
猜你喜欢

RTOS内功修炼记(十) | 深度解析RTOS内核上下文切换机制

Rpc-bdy (5) - automatic service logoff, load balancing

Redis transaction learning

Matlab Simulink hydropower and synchronous motor power generation
![Embedded system transplantation [5] - Cross compilation tool chain](/img/2a/eadaaafe794aa9b3106441fa50ffc7.png)
Embedded system transplantation [5] - Cross compilation tool chain

MySQL learning - MySQL software installation and environment configuration (Windows) details!

Experiment 6 MPEG

Worthington lysozyme technical description and literature reference

Matlab Fractional Order PID control

训练赛《眼不见,心不烦,理不乱》题解
随机推荐
Solution to the problem of "out of sight, out of mind, out of order" in the training competition
Android Development - lambda expression of kotlin syntax
Exercices classiques de langue C (2) - « tri des bulles »
[super complete sorting] Cisco and Huawei order comparison memo, take it away without thanks! Anytime, anywhere
4. Hezhou air32f103_ LCD
MySQL cannot be accessed. Navicat prompt: is not allowed to connect to this MySQL server
Workbnech application of dynamixel steering gear under ROS
Sqlserver backup restore
俄罗斯方块、1
MLP-多层感知机
Remember an online sql deadlock accident: how to avoid deadlock?
High precision phase shift (mcp41xx) program STM32F103, f407 are common, just change the pin (SPI software analog communication)
buu web
Qt ROS相关操作(运行终端指令、发布订阅自定义消息话题或服务、订阅图像并显示)
Svg image color modification is not fancy
C language classic exercises (2) - "bubble sort"“
Matlab sound signal processing frequency diagram signal filtering and playing sound
Matlab Fractional Order PID control
Leetcode (Sword finger offer) - 11. Minimum number of rotation array
Demining game (analysis)