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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask-controller-0.0.2.tar.gz.
File metadata
- Download URL: flask-controller-0.0.2.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
065b804deb02540832d739e6b4e130129893d41aa1c50efd7216718795f2605f
|
|
| MD5 |
3b3aa1f605b49ac50329aae330a23e35
|
|
| BLAKE2b-256 |
b240f84440b4a71645c5cb59d624dc754661659640e3144db3e5960cc014f3bd
|
File details
Details for the file flask_controller-0.0.2-py3-none-any.whl.
File metadata
- Download URL: flask_controller-0.0.2-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f56bee37519abe0eed9c32b41dfdc17b393eda8043db06535b15a6e2aec122c
|
|
| MD5 |
237ff8ad06ade6358adec02c5161f3ae
|
|
| BLAKE2b-256 |
ebb8b5c93778fa73daac1ede7c3f83ddc2be56c5545f2acbf5ac58c9a2ec482f
|