當前位置: 首頁>>代碼示例>>Python>>正文


Python asgi.get_channel_layer方法代碼示例

本文整理匯總了Python中channels.asgi.get_channel_layer方法的典型用法代碼示例。如果您正苦於以下問題:Python asgi.get_channel_layer方法的具體用法?Python asgi.get_channel_layer怎麽用?Python asgi.get_channel_layer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在channels.asgi的用法示例。


在下文中一共展示了asgi.get_channel_layer方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: whois

# 需要導入模塊: from channels import asgi [as 別名]
# 或者: from channels.asgi import get_channel_layer [as 別名]
def whois(request):

    mimetype = 'application/json'

    # Get channel_layer function
    from channels.asgi import get_channel_layer
    from channels.sessions import session_for_reply_channel
            
    # passing group_channel takes channel name
    #channel_layer = get_channel_layer()
    #data = channel_layer.group_channels('notifications')
    #data = channel_layer.global_statistics()
    #data = channel_layer.channel_statistics('notifications')
    #data = get_channel_layer().group_channels('notifications')    
    #data = Group("notifications").extensions
    #data = get_channel_layer().receive_twisted()
    
    #from channels import channel_layers
    #layer = channel_layers["default"]
    #print(layer.router.channels)    
    
    data = []
    
    
    from django.contrib.sessions.backends import cache as engine
    data = get_channel_layer().group_channels('notifications')
    
    active_users = []
    for C in data:        
        #Channel(C).send({"text": json.dumps({'clean_signal':True})})
        c_session = session_for_reply_channel(C)        
        session = engine.SessionStore(c_session._session_key)        
        
        #print(c_session._session['_auth_user_id'])
        #print(session.keys())
        #print(session.get('username', None), session.get_expiry_date())
        
        username = session.get('username', None)
        # this is the same
        # username = c_session.get('username', None)
        if username not in active_users and username != None:
            active_users.append(username)
    data = active_users
            
    
    return HttpResponse(json.dumps(data), mimetype) 
開發者ID:ilavender,項目名稱:sensu_drive,代碼行數:48,代碼來源:views.py


注:本文中的channels.asgi.get_channel_layer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。