I’m using Django 1.3, and I’d like to modify the session middleware to add some methods that will help me out.
In ./settings.py
SESSION_ENGINE='tcore.my_sessions.MySessionStore'
In ./tcore/my_sessions.py:
from django.contrib.sessions.backends.db import SessionStore
from django.contrib.sessions.middleware import SessionMiddleware
from django.conf import settings
class MySessionStore(SessionStore):
....
def my custom methods here
However, I keep getting some weird exceptions when I do this. What’s the proper way to make a custom Session Engine?
AttributeError at /create/
type object 'MySessionStore' has no attribute 'SessionStore'
Request Method: GET
Request URL: http://localhost:8000/create/
Django Version: 1.3.1
Exception Type: AttributeError
Exception Value:
type object 'MySessionStore' has no attribute 'SessionStore'
Python Version: 2.6.1
Looking at the documentation of SESSION_ENGINE, take such an example:
django.contrib.sessions.backends.file. The source of this module defines a SessionStore class. So that’s what you should do too:./tcore/my_sessions.py:
settings.py: