当前位置: 首页>>代码示例>>Python>>正文


Python StreamingHttpResponse.flush方法代码示例

本文整理汇总了Python中django.http.StreamingHttpResponse.flush方法的典型用法代码示例。如果您正苦于以下问题:Python StreamingHttpResponse.flush方法的具体用法?Python StreamingHttpResponse.flush怎么用?Python StreamingHttpResponse.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.http.StreamingHttpResponse的用法示例。


在下文中一共展示了StreamingHttpResponse.flush方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: dispatch

# 需要导入模块: from django.http import StreamingHttpResponse [as 别名]
# 或者: from django.http.StreamingHttpResponse import flush [as 别名]
 def dispatch(self, request, *args, **kwargs):
     response = StreamingHttpResponse(self._queue(),
                                      mimetype='text/event-stream')
     response['Cache-Control'] = 'no-cache'
     response['Software'] = 'opps-liveblogging'
     response.flush()
     return response
开发者ID:kod3r,项目名称:opps-liveblogging,代码行数:9,代码来源:views.py

示例2: dispatch

# 需要导入模块: from django.http import StreamingHttpResponse [as 别名]
# 或者: from django.http.StreamingHttpResponse import flush [as 别名]
    def dispatch(self, request, *args, **kwargs):
        self.slug = self.kwargs.get('slug')
        self.event_obj = self.model.objects.get(
                channel_long_slug=self.get_long_slug(), slug=self.slug)

        response = StreamingHttpResponse(self._queue(),
                                         mimetype='text/event-stream')
        response['Cache-Control'] = 'no-cache'
        response['Software'] = 'opps-liveblogging'
        response['Access-Control-Allow-Origin'] = '*'
        response.flush()
        return response
开发者ID:jeanmask,项目名称:opps-liveblogging,代码行数:14,代码来源:views.py

示例3: match

# 需要导入模块: from django.http import StreamingHttpResponse [as 别名]
# 或者: from django.http.StreamingHttpResponse import flush [as 别名]
def match(request, match_pk, mode='response'):
    """
    :mode:
       response -  Django response JSON
       json - Dumped JSON object
       python - Pure Python Dictionary
    """
    data = data_match(match_pk)

    def _json_response():
        try:
            response = JSONPResponse(
                data, {}, response_mimetype(request), request.GET['callback'])
        except:
            response = JSONResponse(data, {}, response_mimetype(request))
        return response

    if mode == 'response':
        response = _json_response()
        response['Content-Disposition'] = 'inline; filename=files.json'
    elif mode == 'sse':
        def _sse_queue():
            redis = Db('goalservematch', match_pk)
            pubsub = redis.object().pubsub()
            pubsub.subscribe(redis.key)
            while True:
                for m in pubsub.listen():
                    if m['type'] == 'message':
                        data = m['data'].decode('utf-8')
                        yield u"data: {}\n\n".format(data)
                yield
                time.sleep(0.5)

        response = StreamingHttpResponse(_sse_queue(),
                                         mimetype='text/event-stream')
        response['Cache-Control'] = 'no-cache'
        response['Software'] = 'opps-goalserve'
        response.flush()
    elif mode == 'json':
        response = _json_response()
    elif mode == 'python':
        response = data
    else:
        response = \
            "Please specify the mode argument as python, json or response"

    return response
开发者ID:jeanmask,项目名称:opps-goalserve,代码行数:49,代码来源:views.py


注:本文中的django.http.StreamingHttpResponse.flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。