from pyramid.config import Configurator from pyramid.response import Response from pyramid.view import view_config
@view_config(route_name='test')
<!-- lang: python -->
def string_response_adaptr(request):
response = Response('<h1>hello</h1>')
response.content_type = 'text/html'
return response
<!-- lang: python -->
if __name__ == '__main__':
config = Configurator()
config.add_response_adapter(string_response_adaptr)
config_add_response_adanter(string_response_adapter)的作用:调用函数名为string_response_adaptr的函数
本文介绍了一个使用Python编写的Pyramid Web框架中的响应适配器实现方式,该适配器可以将字符串类型的响应转换为HTML格式并返回。


被折叠的 条评论
为什么被折叠?



