当前位置:网站首页>蓝图-类视图方法
蓝图-类视图方法
2022-07-27 05:02:00 【pink_Pig___】
蓝图方法
- 创建两个py文件,app.py文件和user.py文件写入代码
在user.py文件中写入蓝图
from flask import Blueprint
# 实例化对象
user_bp = Blueprint('user_bp', __name__, url_prefix='/user')
@user_bp.route('/register')
def register():
return '注册用户'
- 在app.py中注册蓝图
from flask import Flask
from user import user_bp
# 注册蓝图
app.register_blueprint(user_b)
if __name__ == '__main__':
app.run()
# 路由
# http://127.0.0.1:5000/user/register
类视图方法
- 在user.py文件中写入代码
from flask import Flask
from flask_restful import Api, Resource
user_pb = Blueprint('user_pb', __name__, url_prefix='/user')
@user_bp.route('/register')
def register():
return '注册用户'
#实例化一个Api对象,Api对象的作用是用来搜集路由的
api = Api(user_bp)
# 定义一个类,继承自Resource类,把当前类给伪装成视图类
class Users(Resource):
def get(self):
return '这是类视图的get方法'
def post(self):
return '是类视图的post方法这'
# 第一个参数是类对象,第二个是路由
api.add_resource(Users, '/users')
边栏推荐
- Constraints of MySQL table
- B1024 科学计数法
- JVM Part 1: memory and garbage collection part 14 -- garbage collector
- MQ set expiration time, priority, dead letter queue, delay queue
- Detailed description of binary search tree
- Basic operation of vim
- Three waiting methods of selenium and three processing methods of alert pop-up
- 接收方设置并发量和限流
- B1027 print hourglass
- 消息可靠性处理
猜你喜欢

Raspberry pie RTMP streaming local camera image

JVM上篇:内存与垃圾回收篇二--类加载子系统

mq设置过期时间、优先级、死信队列、延迟队列

Bean's life cycle & dependency injection * dependency auto assembly

idea远程调试debug

JVM上篇:内存与垃圾回收篇五--运行时数据区-虚拟机栈

Typescript details

2021 OWASP top 6-10 collection

Differences among left join, inner join and right join

File processing (IO)
随机推荐
JVM Part 1: memory and garbage collection part 10 - runtime data area - direct memory
B1025 reverse linked list*******
简化JDBC的MyBits框架
稀疏数组→五子棋的存盘续盘等操作
Critical path principle
B1025 反转链表*******
LeetCode刷题之322 Coin Change
B1028 人口普查
pytorch 数据类型 和 numpy 数据 相互转化
File processing (IO)
B1028 census
Scientific Computing Library -- Matplotlib
Raspberry pie RTMP streaming local camera image
LeetCode之268.Missing number
String class
Scientific Computing Library - numpy
Could not autowire. No beans of ‘userMapper‘ type found.
Demo of throttling function -- regular expression matching
conda和pip环境常用命令
JVM Part 1: memory and garbage collection part 6 -- runtime data area local method & local method stack