flask实现页面的跳转
时间: 2024-01-04 07:04:15 浏览: 70
在flask中,可以通过`redirect()`函数实现页面的跳转。具体步骤如下:
1. 在flask中导入`redirect`函数。
```python
from flask import redirect
```
2. 定义相应的路由。
```python
@app.route('/home')
def home():
return "Welcome to the home page!"
```
3. 在路由函数中使用`redirect()`函数进行跳转。
```python
@app.route('/')
def index():
return redirect('/home')
```
在上述代码中,`index()`函数会重定向到`home()`函数,也就是跳转到`/home`路由中。在实际应用中,可以根据具体的需求进行调整。
阅读全文
相关推荐
















