Задать вопрос

Тел: +7 965 3737 888

442

Просмотров

1

Ответов

Accept Header Middleware

<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>
def exampleview(request):
    if request.accepts('application/json'):
        # return a json representation

    if request.accepts('text/html'): 
        # return html

<p>Please note that with this middleware the view defines the priority of the mime-types, not the order in which they where provided in the HTTP-Header. </p>

Вопрос полезен? Да0/Нет0
file_5098.py(391.0б)
None

Ответы (1):

Ответludvig.ericson:10.09.2008
Ответ полезен? Да0/Нет0

I'd say the new.instancemethod trickery is indeed uncalled for:

request.accepts = lambda type: type in acc

Not to mention the list comprehension. :-)