当前位置:网站首页>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')
边栏推荐
- while Loop
- Fluent rendering mechanism - GPU thread rendering
- [geek challenge 2019] finalsql 1
- Development of three database general SQL code based on PG Oracle and MySQL
- Background coupon management
- 开怀一笑
- [ciscn2019 southeast China division]web11 1
- [netding cup 2020 Qinglong group]areuserialz (buuctf)
- Openresty + keepalived 实现负载均衡 + IPV6 验证
- OSI seven layer model and tcp/ip four layer (TCP and UDP) (notes)
猜你喜欢

Node installation and debugging

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

On Valentine's day, I drew an object with characters!

OPPO 自研大规模知识图谱及其在数智工程中的应用

Massive data Xiao Feng: jointly build and govern opengauss root community and share a thriving new ecosystem

Minio 安装与使用

无法获取下列许可SOLIDWORKS Standard,无法找到使用许可文件。(-1,359,2)。

ERP production operation control Huaxia

SSTI template injection

Plato farm is expected to further expand its ecosystem through elephant swap
随机推荐
缓存一致性与内存屏障
XxE & XML vulnerability
Dirsearch[directory scanning tool]
Using ecological power, opengauss breaks through the performance bottleneck
Idea remote debugging
ROS2安装时出现Connection failed [IP: 91.189.91.39 80]
Attack and defense World Lottery
借生态力量,openGauss突破性能瓶颈
Implementation of registration function
Realization of background channel group management function
"Basic knowledge of PHP" implement mathematical operations in PHP
vCenter7.0管理Esxi7.0主机
Implementation of adding function of background user management display
It's better to be full than delicious; It's better to be drunk than drunk
[uni app advanced practice] take you hand-in-hand to learn the development of a purely practical complex project 1/100
Vcenter7.0 managing esxi7.0 hosts
Day6 --- Sqlalchemy advanced
Use of "PHP Basics" Boolean
I drew a Gu ailing with characters!
Flask project configuration