我有以下問題我的數據庫不是空的,並有我需要的記錄。但是,當我查詢分貝它說,沒有這樣的對象匹配給定的查詢。我使用Django通道從websocket查詢數據庫,我的數據庫是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})
,我注意到另一件事是,打印(用戶名)不打印任何東西它只是跳過這一行。我用message.user.username不同功能的作品,所以我敢肯定它應該返回用戶名
回溯:
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.
你可以發佈回溯? –
@RaphaëlGomèsdone – nitheism