小编win*_*ter的帖子

在Shopify App的Django HttpResponse对象中设置Content-Type

我正在使用Django开发Shopify应用程序,我正在使用nginx和gunicorn在VPS上托管.

我正在尝试将HttpResponse对象的Content-Type更改为application/liquid,以便我可以使用Shopify的应用程序代理功能,但它似乎不起作用.

以下是我认为是我的代码的相关部分:

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
Run Code Online (Sandbox Code Playgroud)

根据Django文档,我应该设置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 …
Run Code Online (Sandbox Code Playgroud)

python django http httpresponse shopify

21
推荐指数
2
解决办法
4万
查看次数

标签 统计

django ×1

http ×1

httpresponse ×1

python ×1

shopify ×1