当前位置:网站首页>蓝图-类视图方法
蓝图-类视图方法
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')
边栏推荐
猜你喜欢

Typescript details

2021 OWASP top 4: unsafe design

pyside2____ 1. Installation and case listing

A math problem cost the chip giant $500million

素数筛选(埃氏筛法,区间筛法,欧拉筛法)

笔记系列之docker安装Postgresql 14

ERROR! MySQL is not running, but PID file exists

Prime number screening (Ehrlich sieve method, interval sieve method, Euler sieve method)

JVM Part 1: memory and garbage collection part 14 -- garbage collector

JVM Part 1: memory and garbage collection part 11 -- execution engine
随机推荐
Card drawing program simulation
B1021 single digit statistics
268.missing number of leetcode
How to test the payment process?
B1028 人口普查
Typescript details
During its low-level period, this slave edge causes the instruction number to make a corresponding model
JVM Part 1: memory and garbage collection part 12 -- stringtable
B1022 D进制的A+B
Differences among left join, inner join and right join
Domestic mainstream ERP software market
Laozi cloud and Fuxin Kunpeng achieved a major breakthrough in 3D ofd 3D format documents for the first time
Raspberry pie RTMP streaming local camera image
JVM上篇:内存与垃圾回收篇十一--执行引擎
Gradio quickly builds ml/dl Web Services
Li Kou achieved the second largest result
A math problem cost the chip giant $500million
Set static IP for raspberry pie
idea远程调试debug
Differences among bio, NiO and AIO