djangosnippets.org: Latest snippets tagged with 'accept'http://djangosnippets.org/tags/accept/2010-11-15T14:59:23.404737-06:00Improved Accept middleware with webkit workaround
2010-11-15T14:59:23.404737-06:00raven_nevermorehttp://djangosnippets.org/snippets/2263/<p>An accept middleware, which is based on the code of http://djangosnippets.org/snippets/1042/ but adds a workaround for the buggy accept header, sent from webkit browsers such as safari and chrome.
</p>
<p>The workaround affects any accept header, that has xml and (x)html in the best q, but also the xml mediatype at …</p>
Freely redistributableImproved Accept header middleware
2008-09-10T08:22:11.121237-05:00ludvig.ericsonhttp://djangosnippets.org/snippets/1042/<p>A clean and simple implementation of parsing the Accept header. It places the result in request.accepted_types.</p>
<p>Place this middleware anywhere in the chain, as all it does is add to the request object.</p>
Freely redistributableAccept Header Middleware
2008-04-16T15:54:33.375389-05:00kioopihttp://djangosnippets.org/snippets/708/<p>A middleware that parses the HTTP_ACCEPT header of a request. </p>
<p>The request gets a new method called "accepts" that takes a string and returns True if it was in the list of accepted mime-types.</p>
<p>It makes it possible to write views like:</p>
<pre><code>def exampleview(request):
if request.accepts('application/json'):
# return a json …</code></pre>
Freely redistributable