I have a Django app called chat and the root urls.py looks like this

path('messages/', include('chat.urls')),

However the url below, in the chat app urls.py is causing problems

re_path(r"^(?P<username>[\[email protected]+-]+)", login_required(chat_views.ThreadView.as_view()), name='thread'),

What is happening is that instead of throwing a 404 does not exist error when I go to a made up url such as

localhost/messages/blahblah/02

It instead throws

NOT NULL constraint failed: chat_thread.second_id

Because it is assuming blahblah/02 is a username and is mapping it to the ThreadView which fails to get the thread object from 2 users.

So essentially, any other url pattern I try to create in the chat app doesn't route properly. (Example I tried creating a NotificationListView but couldn't access it due to routing messages/notifications to ThreadView)

How can I stop this from happening?

0 Answers