Skip to content

Instantly share code, notes, and snippets.

@sorl
Created May 1, 2011 23:36
Show Gist options
  • Save sorl/950990 to your computer and use it in GitHub Desktop.
Save sorl/950990 to your computer and use it in GitHub Desktop.
# management command
from django.contrib.staticfiles.management.commands.runserver import Command as StaticFilesCommand
from django.contrib.staticfiles.handlers import StaticFilesHandler
from nimda.globals import _local_manager
class Command(StaticFilesCommand):
def get_handler(self, *args, **options):
handler = super(Command, self).get_handler(*args, **options)
handler = _local_manager.make_middleware(handler)
return handler
# nimda.globals
from werkzeug.local import Local, LocalManager, LocalProxy
_local = Local()
_local_manager = LocalManager([_local])
request = LocalProxy(_local, 'request')
# nimda.middleware
from nimda.globals import _local
class ThreadLocals(object):
def process_request(self, request):
_local.request = request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment