0

1 つのルートに対して複数の応答を送信する方法を探しています。問題は、私が読んだ内容から、コンテンツ データを返さなければならないことです。例えば ​​:

@route('/events')
def positions():      
    for i in xrange(5):        
        response.content_type = 'text/event-stream'        
        response.set_header('Cache-Control', 'no-cache')                
        now = datetime.datetime.now().time().replace(microsecond=0)        
        return  "data: %s\n\n"%now

一部の関数呼び出しの最後の行を置き換える方法はありますか?そのため、すべての応答を送信してからルートを終了できますか?

ありがとう、
オマー。

4

1 に答える 1

0

私はあなたが何を求めているのかを 100% 理解しているとは言えないので、正しく答えられないかもしれませんが、これはあなたが望むことでしょうか?

@route('/events')
def positions():
    output = ''
    for i in xrange(5):
        now = datetime.datetime.now().time().replace(microsecond=0)
        output += "%s\n\n"%now
    response.content_type = 'text/event-stream'                
    response.set_header('Cache-Control', 'no-cache')
    return "data: " + output
于 2012-08-01T23:47:41.103 に答える