Determine the requested content type?

前端 未结 4 1047
不知归路
不知归路 2020-12-18 18:49

I\'d like to write a Django view which serves out variant content based on what\'s requested. For example, for \"text/xml\", serve XML, for \"text/json\", serve JSON, etc. I

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-18 19:12

    'Content-Type' header indicates media type send in the HTTP request. This is used for requests that have a content (POST, PUT).

    'Content-Type' should not be used to indicate preferred response format, 'Accept' header serves this purpose. To access it in Django use: HttpRequest.META.get('HTTP_ACCEPT')

    See more detailed description of these headers

提交回复
热议问题