Simon is a library to help make working with MongoDB easier. Flask-Simon was created to make it even easier to use Simon with your Flask applications.
To install the latest stable version of Flask-Simon:
$ pip install Flask-Simon
or, if you must:
$ easy_install Flask-Simon
To install the latest development version:
$ git clone git@github.com:dirn/Flask-Simon.git
$ cd Flask-Simon
$ python setup.py install
In addition to Flask-Simon, this will also install:
After installing Flask-Simon, import it where you create your Flask app.
from flask import Flask
from flask.ext.simon import Simon
app = Flask(__name__)
Simon(app)
Simon will establish a connection to the database that will be used as the default database for any Model classes that you define.
Simon looks for the following in your Flask app’s configuration:
MONGO_URI | A MongoDB URI connection string specifying the database connection. |
If the MONGO_URI configuration setting is not present, Simon will connect to localhost and use a database named after the Flask app.
Automatically creates a default connection for Simon models.
Initializes the Flask app for use with Simon.
This method will automatically be called if the app is passed into __init__().
Parameters: | app (flask.Flask) – the Flask application. |
---|
Finds and returns a single document, or raises a 404 exception.
This method will find a single document within the specified model. If the specified query matches zero or multiple documents, a 404 Not Found exception will be raised.
Parameters: |
|
---|
Full details of how to use get_or_404() can be found in the Simon API.
For more information, check out the Simon docs and the MongoDB docs.