Skip to content


Subversion checkout URL

You can clone with
Download ZIP
MongoDB backends for Django sessions and authentication (bypasses Django's ORM model)
Latest commit 60aedf0 Vinay Pulim Merge pull request #4 from andresburitica/master
Several bug fixes
Failed to load latest commit information.
mango Raise CreateError based on update's succeess or failure
README.rst updated README initial commit initial commit



To install mango:

sudo python install


To use mango with your Django project, just add these lines to your file:

SESSION_ENGINE = 'mango.session'
AUTHENTICATION_BACKENDS = ('mango.auth.Backend',)
MONGODB_HOST = 'localhost'  # enter your MongoDB hostname here
MONGODB_PORT = None         # enter your MongoDB port here (None for default port)
MONGODB_NAME = 'mydb'       # enter your MongoDB database name here

Also, make sure 'MIDDLEWARE_CLASSES' contains the session and authentication middleware classes:


Django sessions should now work exactly as described in the Django sessions documentation.

For the most part, Django authentication should also work as described in the Django authentication documentation. However, since many of the administrative functions rely on Django's ORM model (which we no longer have with mongodb), you can't use the User model described in the Django documentation to directly manipulate User objects. Instead, mango provides its own User class that you should use instead. All of Django's original User class instance methods are available in mango's User class (is_authenticated(), set_password(), check_password(), etc...). However, there is longer a User.objects attribute. Instead, many of the administrative function such as create_user() are now class methods of User.

For instance, to create a user:

>>> from mango.auth import User
>>> user = User.create_user('john', '', 'johnpassword')

To find a user:

>>> from mango.auth import User
>>> user = User.get({'username': 'john'})

To modify a user's attributes:

>>> from mango.auth import User
>>> user = User.get({'username': 'john'})
>>> user.first_name = 'John'
>>> user.last_name = 'Lennon'

To delete a user:

>>> from mango.auth import User
>>> user = User.get({'username': 'john'})
>>> user.delete()

If you want direct access to the database connection from anywhere in your Django app:

>>> from mango import database as db
>>> db.users.find()
>>> db.sessions.find()


Support for permissions and groups is not available yet, but is coming soon.

Something went wrong with that request. Please try again.