Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nanozuki/flask-mongonorm
Flask extension for MongoNorm
https://github.com/nanozuki/flask-mongonorm
Last synced: about 2 months ago
JSON representation
Flask extension for MongoNorm
- Host: GitHub
- URL: https://github.com/nanozuki/flask-mongonorm
- Owner: nanozuki
- License: bsd-2-clause
- Created: 2017-04-12T11:42:38.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-04-18T10:04:13.000Z (over 7 years ago)
- Last Synced: 2024-10-06T11:08:10.929Z (3 months ago)
- Language: Python
- Size: 13.7 KB
- Stars: 1
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
Flask-MongoNorm
===============`中文文档 `_
MongoNorm support for Flask applications.
installation
------------Use pip to install::
pip install Flask-MongoNorm
Use guide
---------1. Init by Flask app
As Mostly Flask Extension, there are two methods to init Flask-MongoNorm.
You can init by app directly::from flask_mongonorm import MongoClient
client = MongoClient(app)
db = client.testOr you can init Flask-MongoNorm by `init_app`::
client = MongoClient()
db = client.testclient.init_app(app)
**Tips about lazy load:**
Until you use your model class or call methods of MongoClient or Database,
it won't try to connect to Mongo Server.Notice the example below, You can make db before `init_app`. This feature can`
let you use decorator `@db.collection("article")` without exception of
"no application bound"2. Some useful tools.
* shortcut for find a document or raise 404::
Article.find_one_or_404({'title': 'Flask-MongoNorm'})
* A json encoder for ObjectId and Datetime::
from flask_mongonorm import BSONEncoder
app.json_encoder = BSONEncoderthis encoder will encode ObjectId to str and datetime to unix time(seconds).