当前位置:网站首页>Blueprint class view method
Blueprint class view method
2022-07-27 08:33:00 【pink_ Pig___】
Blueprint method
- Create two py file ,app.py Document and user.py File write code
stay user.py Write the blueprint in the file
from flask import Blueprint
# Instantiate objects
user_bp = Blueprint('user_bp', __name__, url_prefix='/user')
@user_bp.route('/register')
def register():
return ' Registered users '
- stay app.py Registration blueprint
from flask import Flask
from user import user_bp
# Registered blueprint
app.register_blueprint(user_b)
if __name__ == '__main__':
app.run()
# route
# http://127.0.0.1:5000/user/register
Class view method
- stay user.py Write code in file
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 ' Registered users '
# Instantiate a Api object ,Api Object is used to collect routes
api = Api(user_bp)
# Define a class , Inherited from Resource class , Disguise the current class as a view class
class Users(Resource):
def get(self):
return ' This is a class view get Method '
def post(self):
return ' Is a class view post Method this '
# The first parameter is the class object , The second is routing
api.add_resource(Users, '/users')
边栏推荐
- Realize SKU management in the background
- Risk control and application of informatization project
- OSI seven layer model and tcp/ip four layer (TCP and UDP) (notes)
- P7 Day1 get to know the flask framework
- The response of the database interface is very slow
- 关于数据库的接口响应非常慢
- [NPUCTF2020]ReadlezPHP 1
- Flask one to many database creation, basic addition, deletion, modification and query
- Graph node deployment and testing
- Luogu super Mary game
猜你喜欢

带宽 与 货币

Element display mode: block level, inline, inline block, nesting specification, display mode conversion

Plato farm is expected to further expand its ecosystem through elephant swap

永久设置source的方法

One book 1201 Fibonacci sequence

面试官:什么是脚手架?为什么需要脚手架?常用的脚手架有哪些?

Day3 -- flag state holding, exception handling and request hook

Realization of backstage brand management function

OPPO 自研大规模知识图谱及其在数智工程中的应用
![[ciscn2019 southeast China division]web11 1](/img/94/61ad4f6cbbd46ff66f361462983d7a.png)
[ciscn2019 southeast China division]web11 1
随机推荐
After installing mysql, docker entered the container and found that he could not log in to MySQL
"PHP Basics" PHP statements and statement blocks
ERP production operation control Huaxia
JS basic exercises
Flask request data acquisition and response
[netding cup 2020 rosefinch group]nmap 1 two solutions
【uni-app高级实战】手把手带你学习一个纯实战复杂项目的开发1/100
借生态力量,openGauss突破性能瓶颈
Bandwidth and currency
Luogu super Mary game
It's better to be full than delicious; It's better to be drunk than drunk
Openresty + keepalived to achieve load balancing + IPv6 verification
Openresty + keepalived 实现负载均衡 + IPV6 验证
All in one 1319 - queue for water
STM32小bug汇总
Realize SKU management in the background
Design and development of GUI programming for fixed-point one click query
VS Code中#include报错(新建的头文件)
[ciscn2019 southeast China division]web11 1
Idea remote debugging