22

私は、nginx と gunicorn を使用して VPS でホストしている Django を使用して Shopify アプリに取り組んでいます。

application/liquidShopify のアプリケーション プロキシ機能を使用できるように、HttpResponse オブジェクトの Content-Type を に変更しようとしていますが、機能していないようです。

これが私のコードの関連セクションであると私が信じているものです:

from django.shortcuts import render_to_response, render
from django.http import HttpResponse
from django.template import RequestContext
import shopify
from shopify_app.decorators import shop_login_required

def featured(request):
   response = HttpResponse()
   response['content_type'] = 'application/liquid; charset=utf-8'
   response['content'] = '<html>test123</html>'
   response['Content-Length'] = len(response.content)
   return response

Django docsによると、ヘッダーresponse[''content_type]に設定するために設定する必要があります。Content-Type残念ながら、views.py でこの関数に対応する URL にアクセスすると、200 応答が返されますが、Content-Type は変更されておらず、Content-Length は 0 です。応答ヘッダーは次のとおりです。

HTTP/1.1 200 OK
Server: nginx
Date: Tue, 09 Jul 2013 12:26:59 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 0
Connection: keep-alive
X-Request-Id: 2170c81fb16d18fc9dc056780c6d92fd
content: <html>test123</html>
vary: Cookie
content_type: application/liquid; charset=utf-8
P3P: CP="NOI DSP COR NID ADMa OPTa OUR NOR"

に変更response['content_type']するとresponse['Content-Type']、次のヘッダーが表示されます。

HTTP/1.1 200 OK
Server: nginx
Date: Tue, 09 Jul 2013 12:34:09 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 3097
Connection: keep-alive
X-Request-Id: 76e67e04b753294a3c37c5c160b42bcb
vary: Accept-Encoding
status: 200 OK
x-shopid: 2217942
x-request-id: 6e63ef3a27091c73a9e3fdaa03cc28cb
x-ua-compatible: IE=Edge,chrome=1
p3p: CP="NOI DSP COR NID ADMa OPTa OUR NOR"
content-encoding: gzip
P3P: CP="NOI DSP COR NID ADMa OPTa OUR NOR"

応答の Content-Type を変更する方法についてのアイデアはありますか? これは、nginx または gunicorn の構成に問題があるのでしょうか?

ご協力いただきありがとうございます!

4

4 に答える 4

5

だからこれは私のために働いた:

def featured(request):
  response = HttpResponse("", content_type="application/liquid; charset=utf-8")
  response['Content-Length'] = len(content)
  response.write('<html>test123</html>')
  return response

皆さん、助けてくれてありがとう!

于 2013-07-09T13:57:30.520 に答える
4

ドキュメントの指示に従うと、次のようになります。

# set content_type
response = HttpResponse("",
                        content_type="application/liquid; charset=utf-8")
# add content
response.write('<html>test123</html>')

お役に立てれば!

于 2013-07-09T12:48:58.437 に答える