[Answered ]-Trouble logging out user in Django

2đź‘Ť

âś…

The problem has nothing to do with your logout function itself. It is simply a function of your URL configuration. The pattern for your “detail” function is just r'^(?P<username>\w+)/$', which will also match the string “logout”. So, when a user clicks on a link to logout, Django will route it to the “detail” view, which will attempt to find a user named “logout” and fail with the error you see.

You can easily fix this by moving your “logout” pattern above the “detail” one in urls.py, since URLs are matched in order.

Leave a comment