1

"application/json"基本的に、ユーザーがそれを介して要求した場合に、アプリケーションをRESTfulにするために、Pylonsのミドルウェアを使用してヘッダーを変更しようとしていますGET

私が持っている質問は、変数headersは基本的に長いリストです。このように見える:

[('Content-Type', 'text/html; charset=utf-8'), ('Pragma', 'no-cache'), ('Cache-Control', 'no-cache'), ('Content-Length','20'), ('Content-Encoding', 'gzip')]

今、私はリクエストに基づいて値を変更することを探していますが、これらの位置は固定されていますか?'Content-Type'常にポジションになりheaders[0][0]ますか?

よろしくお願いします、

アンダース

4

1 に答える 1

1

これを試して


from webob import Request, Response
from my_wsgi_application import App
class MyMiddleware(object):
    def init(self, app):
        self.app = app
    def call(self, environ, start_response):
        req = Request(environ)
... rsp = req.get_response(app) rsp.headers['Content-type'] = 'application/json' return rsp(environ, start_response)

または、単純なdo request or response .headers ['Content-type'] ='application / json' in you contoller

http://pythonpaste.org/webob/reference.html#headersを参照してください

于 2010-05-05T10:06:39.520 に答える