Django Problem "No User matches the given query"

So, how about this for annoying. I was developing my site and suddenly started having all these pages started having 404 errors with the following text:

No User matches the given query.

No matter what I did, all the login pages were failing. I thought it was a problem with the database, or my code somewhere, but no changes were having an effect. I couldn't figure out what changed, so I did some research and found this simple, albeit less-than-obvious solution.

Basically, my urls.py was not in a good order. The first rule in my file was matching urls like the following:

/users/<<username>>

All urls in this application all have /users/ preceding them, and the rule in question was to match the user names. Since it was the first rule, it matched for anything like /users/* ... or, all the rules i would ever add there.

Moving that rule to the end of my urls.py file got me back up and running. Though, I'm not sure when or why I moved it initially; which is worrying, since I didn't bother to check the consequences of this seemingly innocuous change.

 


Empower yourself. Never wait for the unfortunate to give you strength.
© 2008, Andrew Holloway. Rights Reserved.

Theme based on Light Theme, ported by Nick Young