Skip to content

Instantly share code, notes, and snippets.

@lorin
Created January 7, 2013 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lorin/4478637 to your computer and use it in GitHub Desktop.
Save lorin/4478637 to your computer and use it in GitHub Desktop.
Annotate a request object with session. Useful for requests that are generated by the RequestFactory for testing
from django.contrib.sessions.middleware import SessionMiddleware
def add_session_to_request(request):
"""Annotate a request object with a session"""
middleware = SessionMiddleware()
middleware.process_request(request)
request.session.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment