本文整理汇总了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
示例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
示例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