A small example package
Project description
Businessman Package
CRUD Business Logic with auto-generator controller for flask-restx.
example:
import what you need
from flask import Blueprint
from flask_mongoengine import Document
from mongoengine import StringField
from businessman import crud_controller_factory
MongoEngine model:
from flask_mongoengine import Document
from mongoengine import StringField
class SampleModel(Document):
meta = {"collection": "SampleModel"}
name = StringField()
code = StringField()
Restx Schema model:
from flask_restx import Api, fields
sample_schema = {
'name': fields.String(required=True, description=''),
'code': fields.String(required=True, description=''),
}
Blueprint and NameSpace:
blueprint = Blueprint('api', __name__)
api = Api(
blueprint,
title='Calendar API Service',
version='1.0',
description='A description',
# All API metadatas
)
ns1 = crud_controller_factory(model=SampleModel, schema_class=sample_schema)
api.add_namespace(ns1)
all of the above is for api.py
:
- define a flask blueprint
- create a
restx.Namespace
from defined model withcrud_controller_factory
function tools - add this namespace to the blueprint
- add the blueprint to the
flask.App
object
flask app.py
:
from flask import Flask
from flask_mongoengine import MongoEngine
from api import blueprint
app = Flask(__name__)
db = MongoEngine()
app.config.from_pyfile("config.py")
db.init_app(app)
app.register_blueprint(blueprint)
if __name__ == "__main__":
app.run(debug=True)
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
businessman-0.0.30.tar.gz
(6.0 kB
view hashes)
Built Distribution
Close
Hashes for businessman-0.0.30-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 275551cdc4fd2450711c32810234fc6f67afe53825dfe2e7da6cbff89d5b6359 |
|
MD5 | 8e54a9f4d60502d594d79238f1832fe4 |
|
BLAKE2b-256 | a6949643169d297b6f9f36076d7fa9fe2e61710f3968178f0556761e8e82da55 |