a extension for flask which can auto register route rule
Project description
flask-controller
简介
flask-controller 简化Flask开发,自动路由注册,以类的形式管理控制器
支持多层扫描
安装
pip install flask-controller
使用示例
项目结构
.
└── flask_app
├── controllers
│ ├── __init__.py
│ ├── admin
│ │ ├── __init__.py
│ │ └── login_controller.py
│ ├── index_controller.py
│ └── user_controller.py
└── main.py
文件内容
flask_app/controllers/index_controller.py
# -*- coding: utf-8 -*-
from flask_controller import FlaskController
class IndexController(FlaskController):
def index(self):
return 'index'
flask_app/controllers/user_controller.py
# -*- coding: utf-8 -*-
from flask_controller import FlaskController
class UserController(FlaskController):
def user_name(self, name, age: int = 23):
return 'username'
flask_app/controllers/admin/login_controller.py
# -*- coding: utf-8 -*-
from flask_controller import FlaskController
class LoginController(FlaskController):
def index(self):
return 'Login index'
flask_app/main.py
# -*- coding: utf-8 -*-
from flask import Flask
from flask_controller import FlaskControllerRegister
app = Flask(__name__, static_folder=None)
# 自动注册路由
register = FlaskControllerRegister(app)
register.register_package('flask_app.controllers')
注册结果
Map([
<Rule '/admin/login/index' (OPTIONS, GET, HEAD, POST) -> admin.login.index>,
<Rule '/index/index' (OPTIONS, GET, HEAD, POST) -> index.index>,
<Rule '/user/user_name/<name>/<age>' (OPTIONS, GET, HEAD, POST) -> user.user_name>
])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
flask-controller-0.0.2.tar.gz
(5.0 kB
view hashes)
Built Distribution
Close
Hashes for flask_controller-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f56bee37519abe0eed9c32b41dfdc17b393eda8043db06535b15a6e2aec122c |
|
MD5 | 237ff8ad06ade6358adec02c5161f3ae |
|
BLAKE2b-256 | ebb8b5c93778fa73daac1ede7c3f83ddc2be56c5545f2acbf5ac58c9a2ec482f |