Just a small example:
@@ python @@ class MyView(ctn.AbstractCTNView): ctn_accept_binding = { 'text/html': 'html_handler', 'text/*': 'plain_handler', '/': 'plain_handler', }
def html_handler(self, request, *args, **kwargs):
return HttpResponse('Hello World', mimetype='text/html')
def plain_handler(self, request, *args, **kwargs):
return HttpResponse('Hello World', mimetype='text/plain')
myview = oopviews.create_view(MyView) @@
This view would accept basically every request for text and give only for text/html provides a different output. Please note, though, that this is by no means a complete implementation of content-type negotiation. The specs also mention additional type-parameters, that are no further described, so I couldn't really add support for them. But for most cases, this implementation should suffice :-)
blog comments powered by Disqus