Skip to content

Instantly share code, notes, and snippets.

@nowells
Created September 8, 2010 23:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nowells/571027 to your computer and use it in GitHub Desktop.
Save nowells/571027 to your computer and use it in GitHub Desktop.
from django.http import HttpRequest
class PickleableHttpRequest(HttpRequest):
def __init__(self, request=None, attributes=None):
super(PickleableHttpRequest, self).__init__()
if request:
if not isinstance(request, HttpRequest):
raise Exception('Request supplied is not a valid HTTP request object.')
self.GET = request.GET
self.POST = request.POST
self.REQUEST = request.REQUEST
# Do not load FILES or META. These structures can't be pickled
if attributes:
for attribute in attributes:
if hasattr(request, attribute):
setattr(self, attribute, getattr(request, attribute))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment