4 Feb 2013 sness   » (Journeyer)

Django snippets: Accept Header Middleware

Django snippets: Accept Header Middleware: "Accept Header Middleware

import new

def accepts( self, mime ):
return mime in self.accepted_types

class AcceptMiddleware(object):
def process_request(self, request):
acc = [a.split(';')[0] for a in request.META['HTTP_ACCEPT'].split(',')]
setattr(request, 'accepted_types', acc )
request.accepts = new.instancemethod(accepts, request, request.__class__)
return None"

'via Blog this'

Syndicated 2013-02-04 05:24:00 from sness

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!