2017-02-17 18 views
0

私は以下の問題があります。データベースが空ではなく、必要なレコードがあります。しかし、私はdbにクエリを実行すると、指定されたクエリに一致するオブジェクトは存在しないと言います。私はWebSocketの中からdjango-channelsを使ってdbに問い合わせ、私のデータベースはpostgreSQLです。Djangoオブジェクトが指定されたクエリと一致しますが、

は、私はこれについて他の質問があることを認識していますし、私は彼らに見えたが、彼らは私の場合ではなく、

ここで何で私を助けないすべての空のデータベースまたは間違ったURLスラグについてです

@channel_session_user_from_http 
def ws_receive(message): 
    username = message.user.username 
    print(username) 
    text = json.loads(message['text']).get('text') 
    # Use my algorithm here 
    score = score_argument.get_rating(text) 
    # find the room with our users 

    current_room = get_object_or_404(PairUsers, Q(username_a=username) | Q(username_b=username)) 

    # current_room = PairUsers.objects.filter(Q(username_a=username) | Q(username_b=username)).first() 

    # check which user you got and send the message to the other 
    if current_room.username_b == username: 
     current_room.score_b = score 
     other_channel = Channel(current_room.reply_channel_a) 
     message.reply_channel.send({'text': text}) 
     other_channel.send({'text': text}) 
    else: 
     current_room.score_a = score 
     other_channel = Channel(current_room.reply_channel_b) 
     message.reply_channel.send({'text': text}) 
     other_channel.send({'text': text}) 

私が気づいた別のことは、この行をスキップするだけのものは印刷しないということです。

Traceback (most recent call last): 
    File "C:\Program Files (x86)\Python35\lib\site-packages\channels\worker.py", line 119, in run 
    consumer(message, **kwargs) 
    File "C:\Program Files (x86)\Python35\lib\site-packages\channels\sessions.py", line 180, in inner 
    result = func(message, *args, **kwargs) 
    File "C:\Program Files (x86)\Python35\lib\site-packages\channels\auth.py", line 73, in inner 
    return func(message, *args, **kwargs) 
    File "C:\Program Files (x86)\Python35\lib\site-packages\channels\sessions.py", line 64, in inner 
    return func(message, *args, **kwargs) 
    File "C:\Program Files (x86)\Python35\lib\site-packages\channels\auth.py", line 89, in inner 
    return func(message, *args, **kwargs) 
    File "C:\Users\nithe\Desktop\debateit\play\consumers.py", line 51, in ws_receive 
    current_room = get_object_or_404(PairUsers, Q(username_a=username) | Q(username_b=username)) 
    File "C:\Program Files (x86)\Python35\lib\site-packages\django\shortcuts.py", line 93, in get_object_or_404 
    raise Http404('No %s matches the given query.' % queryset.model._meta.object_name) 
django.http.response.Http404: No PairUsers matches the given query. 
+0

トレースバックを投稿できますか? –

+0

@RaphaëlGomèsdone – nitheism

答えて

0

message.user.usernameはもちろんのクエリの意志が失敗し、Noneように見える:私はので、私はそれがユーザ名に

トレースバックを返す必要があります確信して動作します別の関数でmessage.user.usernameを使用しました。この質問はデータベースの問題ではありません(まだ)、それはchannelsと関連しています。
message.user.__dict__を印刷して、目的のオブジェクトと一致するかどうか確認してください。

+0

空の辞書が印刷されます。つまり、送信したユーザーは記録されません。 – nitheism

+0

あなたの 'websocket'接続に問題があるようです。しかしそれは別の質問のためだと私は思う。すべてのファイル(ルーティング、あなたが持っているjなど)を提供してください。 –

関連する問題