【Python】Web学习笔记_flask(1)——模拟登录

安装flask

复制代码
pip3 install flask

第一部分内容:

1、主页面输出hello world

2、根据不同用户名参数输出用户信息

3、模拟登录

python 复制代码
from flask import Flask,url_for,redirect

app=Flask(__name__)

@app.route('/')
def index():
    return 'hello world'

@app.route('/user/<uname>')
def show_user_profile(uname):
    #显示用户名信息
    return f'用户名是:{uname}'


@app.route('/post/<int:uid>')
def show_user(uid):
    #显示用户id信息
    return f'用户id是:{uid}'


@app.route('/login')
def login():
    #模拟登录流程
    flag='success'
    #如果登录成功,跳转首页
    if flag:
        return redirect(url_for('index'))
    return '登录页面'


if __name__=='__main__':
    app.run(
        debug=True,
        port=8000
    )

输入连接:http://127.0.0.1:8000/login

相关推荐
BD_Marathon3 小时前
安装Jupyter notebook
ide·python·jupyter
Zlzxzw3 小时前
End-to-End Autonomous Generation of Human Assembly Plans
python
Wellijohn3 小时前
2000 个请求、30% 失败率:我把 Python 批量并发的限流和重试参数算了一遍
后端·python·性能优化
feixing_fx5 小时前
解构与展开:可读性和性能的取舍
开发语言·前端·javascript·前端框架
Logintern095 小时前
deep agents 多智能体模式——规划与委派
python·langchain
前端架构师-老李6 小时前
html教程:header、nav、main、footer 四个标签各管哪一块?
前端·html
烟雨空灵7 小时前
25 天做了个独立开发者作品橱窗,收录 340+ 件作品,代码全开源
前端·node.js
wangruofeng7 小时前
怎么让你的项目更好看?用 UI Lab 练设计原则,给界面去 AI 味
前端·aigc·ai编程
2601_967980117 小时前
Python 办公自动化合集 ⑰:Excel自动计算——总和/平均分/最大值
python·pycharm·办公自动化·数据处理·excel自动计算
用户69371750013848 小时前
AI 越强,为什么我们反而越来越担心失业?
前端·后端·github