matching query does not exist Error in Django
I have implemented a password recovery functionality in django. With my method the new password will be sent to his email id entered. And its working fine when i give the correct email (e-mail id which exists in the database). But when i give an email id which is not in the database, it gives me this error 'DoesNotExist at /forgotPassword/
UniversityDetails matching query does not exist.'. Can somebody help to solve this. Will paste my code here. Can somebody help me to solve this problem.
def forgotPassword(request): if request.POST: email=request.POST.get("email") user = UniversityDetails.objects.get(email=email) if(not user): print "No user" return render_to_response("forgotPassword.html") else: newPassword = user.password send_mail('Password Recovery', 'The password for your site is '+ newPassword, 'email@example.com', ['firstname.lastname@example.org'], fail_silently=False) return render_to_response("passwordRecovery.html") return render_to_response('forgotPassword.html')
<form name="forgotPassword" method="POST" id="myFormid" action="http://10.1.0.90:8080/forgotPassword/"> <div style="float:center;width:100%;color:#0000A0"> Enter your E-mail ID</label><br/> <input type="text" name="email" size="25" /> <input type="submit" value="Submit" /> </div> </form >
try: user = UniversityDetails.objects.get(email=email) except UniversityDetails.DoesNotExist: user = None
I also see you're storing your passwords in plaintext (a big security no-no!). Why don't you use the built-in auth system?
Django error - matching query does not exist, matching query does not exist. Keep getting this error the function thats causing it is.. class TeamAddPlayerView(LoginRequiredMixin, PlayerActionMixin, matching query does not exist. I have tried all the solutions I have found online, however none have worked yet, so I came here to try and find the answer. This is using the latest version of Django.
I also had this problem. It was caused by the development server not deleting the django session after a debug abort in Aptana, with subsequent database deletion. (Meaning the id of a non-existent database record was still present in the session the next time the development server started)
To resolve this during development, I used
matching query does not exist : django, weblate: ERROR Internal Server Error: /translate/annie/app/ar/ File "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 387, in get self.model. DoesNotExist: Permission matching query does not exist. The Site object for your Django project is missing. Each Django project has a Site object which contains the site's name and domain. It is usually automatically created when creating a Django project (in particular, when the syncdb command runs) but in your case it seems that didn't happen.
As mentioned in Django docs, when
get method finds no entry or finds multiple entries, it raises an exception, this is the expected behavior:
get() raises MultipleObjectsReturned if more than one object was found. The MultipleObjectsReturned exception is an attribute of the model class.
get() raises a DoesNotExist exception if an object wasn’t found for the given parameters. This exception is an attribute of the model class.
Using exceptions is a way to handle this problem, but I actually don't like the ugly
try-except block. An alternative solution, and cleaner to me, is to use the combination of
user = UniversityDetails.objects.filter(email=email).first()
When you do
.first() to an empty queryset it returns
None. This way you can have the same effect in a single line.
The only difference between catching the exception and using this method occurs when you have multiple entries, the former will raise an exception while the latter will set the first element, but as you are using
get I may assume we won't fall on this situation.
first method was added on Django 1.6.
DoesNotExist: Group matching query does not exist. · Issue #1089 , Describe the bug Hi, Sorry if this is a user error on my side and I'm wasting your time, I could easily install and integrate django-simple-history into my app: the m. DoesNotExist: ContentType matching query does not exist. But as the Django docs said, in Django unit test, the model used database is not the real product database, it is a temporary database which is created when the unit test start and destroyed after the unit test stop, so the User model object whose username is ‘tom’ do not exist during the unit test execution.
You can use this in your case, it will work fine.
user = UniversityDetails.objects.filter(email=email).first()
Admin Integration broken: ContentType matching query does not , Setting matching query does not exist. File "C:\Python25\lib\site-packages\django\db\models\query.py" in get Exception Type: DoesNotExist at /browse/ aren't sure why you are getting an error, please ask on the django-users mailing list, Questions: I have implemented a password recovery functionality in django. With my method the new password will be sent to his email id entered. And its working fine when i give the correct email (e-mail id which exists in the database). But when i give an email id which is not in the database, it
You may try this way. just use a function to get your object
def get_object(self, id): try: return UniversityDetails.objects.get(email__exact=email) except UniversityDetails.DoesNotExist: return False
#7779 (Setting matching query does not exist.) – Django, misleading error message if get_or_create not provided with defaults provided, the exception thrown is DoesNotExist: Blah matching query does not exist. problem with get_or_create that took most of today to find (I'm a Django newbie). Django - matching query does not exist Question: Tag: django. im working on a django project and im getting this error, "State matching query does not exist." why is
#6970 (misleading error message if get_or_create not provided with , matching query does not exist Error in Django. I have implemented a password recovery functionality in django. With my method the new password will be sent Questions: I’m going through the standard Django tutorial to create an admin for an app. After commenting the admin related stuff in settings and running syncdb I’m getting this message: DoesNotExist at /admin/ Site matching query does not exist.
matching query does not exist Error in Django, When i erase a user from django admin this error it's made in the cms log. So i need some help in here please. Aug 3 11:17:58 edx2 django.contrib.auth.models.DoesNotExist: Group matching query does not exist. please give me the solution. the problem arrise when I change my database db.sqllite3 to postgress
DoesNotExist: User matching query does not exist., When i erase a user from django admin this error it's made in the cms log. So i need some help in here please. Aug 3 11:17:58 edx2 [ The MultipleObjectsReturned exception is raised by a query if only one object is expected, but multiple objects are returned. A base version of this exception is provided in django.core.exceptions; each model class contains a subclassed version that can be used to identify the specific object type that has returned multiple objects.