美文网首页
5、响应输出

5、响应输出

作者: 马小跳_ | 来源:发表于2018-06-03 11:53 被阅读10次

write

def write(self, chunk):
    """Writes the given chunk to the output buffer.

    To write the output to the network, use the flush() method below.

    If the given chunk is a dictionary, we write it as JSON and set
    the Content-Type of the response to be ``application/json``.
    (if you want to send JSON as a different ``Content-Type``, call
    set_header *after* calling write()).

    Note that lists are not converted to JSON because of a potential
    cross-site security vulnerability.  All JSON output should be
    wrapped in a dictionary.  More details at
    http://haacked.com/archive/2009/06/25/json-hijacking.aspx/ and
    https://github.com/facebook/tornado/issues/1009
    """
    pass

将chunk数据写到输出缓冲区。

缓冲区数据刷新到浏览器是由socket来控制。

缓冲区刷新的几种方式:

  • 程序结束
  • 手动刷新
  • 缓冲区满了
  • 遇到\n

示例:

class DocHandler(RequestHandler):
    def get(self, document_id, *args, **kwargs):
        self.write(chunk=document_id)
        self.write("\r\n")
        self.write(chunk={'a': 1, 'b': 2})  # 利用write方法写json数据

finish

刷新缓冲区,关闭当次请求通道

不要在finish下边write

相关文章

  • 5、响应输出

    write 将chunk数据写到输出缓冲区。 缓冲区数据刷新到浏览器是由socket来控制。 缓冲区刷新的几种方式...

  • 2020-07-03 编排InvokeHttp组件默认对收到的H

    调整该组件的延迟时长为0秒,允许收到5xx响应时,及时完成处理。 另可设置组件的总是响应输出为true, 并禁用组...

  • 2018-07-20

    response对象输出响应信息 response.getCharacterEncoding()响应的字符编码集 ...

  • JavaWeb——response

    功能:设置响应消息 1.设置响应行 格式: 设置状态码: 2.设置响应头 3.设置响应体 使用步骤: 1、获取输出...

  • 简单JSON处理(重点)

    跨团队操作可以给所有团队响应JSON。或者响应xml格式数据。把响应返回的数据需要输出为json格式。 之前的方式...

  • Shiny学习(四)||响应式输出

    Shiny应用程序中控件选中的值可以通过生成响应式输出来显示。用户切换控件的值,输出的文本也随着控件的值自动响应。...

  • 单片机操作与应用作业

    按键操作及应用 按键输入 ---->处理---->响应---->输出---->外设代码:

  • 九、HTML5响应式布局

    @(HTML5)[相应式布局] [TOC] 九、HTML5响应式布局 什么是响应式网页设计(布局) 响应式网页设计...

  • 响应式对象

    看vue源码,梳理一下响应式对象输入 输出 实现

  • nodejs中的querystring模块

    form表单发送数据给 然后后台加以响应 最后输出的结果为

网友评论

      本文标题:5、响应输出

      本文链接:https://www.haomeiwen.com/subject/xakjsftx.html