cherrypy 앱이 있는데 응답 헤더 Content-type을 변경하려고합니다. 나는 cherrypy.response.header [ 'Content-Type'] = 'text/plain'으로 해보려고합니다. 불행히도 나는 여전히 'text/html'을 얻고있다. ok 요청에 대해 하나의 콘텐츠 형식을 설정하고 오류 메시지에 대해 다른 콘텐츠 형식을 설정하려고합니다. 콘텐츠 유형을 어떻게 바꿀 수있는 유일한 방법은 내 데코레이터입니다. 그러나이 메서드에 대한 집합 형식 및이를 변경해야합니다. 어디서 문제가 될 수 있는지 아십니까? 내 설정 :Cherrypy 및 content-type
config = {
'/': {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.response_headers.on': True,
'tools.response_headers.headers': [('Content-Type', 'text/html')],
}
}
def GET(self, id):
cherrypy.response.headers['Content-Type'] = 'application/x-download'
somecode
if res < None:
cherrypy.response.headers['Content-Type'] = 'text/plain'
cherrypy.response.status=404
GET._cp_config = {'response.stream': True}
'404 Not Found'에 대한 사용자 정의 응답을 보내려고하십니까? 이것을 확인하십시오 : https://github.com/cherrypy/cherrypy/blob/master/cherrypy/_cperror.py#L49-L111 맞춤 응답을 생성하기 위해 맞춤식 호출 가능을 설정할 수 있습니다. – webKnjaZ
불행히도 작동하지 않습니다. 나는 cherrypy.expose()로 플레이하려고 노력했으며 행동은 약간 변하고있다. 아무도 날 어떻게 설명 할 수 있습니까? – George
정확히 무엇입니까? 달성하려는 내용에 대해 자세히 설명하고보다 완전한 코드 스 니펫을 제공하십시오. – webKnjaZ