Skip to content

Instantly share code, notes, and snippets.

@hirokiky
Created May 29, 2014 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hirokiky/0aded20d0d0896ac1dce to your computer and use it in GitHub Desktop.
Save hirokiky/0aded20d0d0896ac1dce to your computer and use it in GitHub Desktop.
Django Middleware to add attribute for Accept header of HTTP
class AcceptMiddleware(object):
""" Middleware to add attribute for Accept header of HTTP
"""
def process_request(self, request):
acc = [a.split(';')[0] for a in request.META['HTTP_ACCEPT'].split(',')]
setattr(request, 'accepted_types', acc)
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment