Hello everyone!
In addition to login and logout views, django's auth app has views that can let users reset their password if they forget it. Let'...
For further actions, you may consider blocking this person and/or reporting abuse
Hi, Thanks for this tutorial. I'm having some trouble receiving password reset email. I didn't get any error message in my console. I tested my SMTP server online and it works fine.
I'm getting the following output:
[05/Nov/2022 20:49:36] "GET /pr/ HTTP/1.1" 200 3657
[05/Nov/2022 20:49:39] "POST /pr/ HTTP/1.1" 302 0
[05/Nov/2022 20:49:39] "GET /pr/ HTTP/1.1" 200 4128
But didn't receive any mail.
Hi, thanks for the feedback.
Did you check your spam folder?
Yes. It's not even there.
Hi Hana
You may have mentioned this is your other posts but I thought I would highlight it.
As we are extending existing system templates the order of the INSTALLED_APPS in the settings.py file matters.
Django will look for the first View, Form, or Template that matches, so your new template must come before the default version.
For example the Users app comes before the django.contrib.admin & django.contrib.auth apps, as below.
INSTALLED_APPS = [
# Project Apps
"Users",
Thank you for the comment. This section of the doc explains it clearly docs.djangoproject.com/en/4.1/ref/...
Hi, Thank you for this tutorial. I have the following error for reset password. Would you please help me:
SMTPAuthenticationError at /password-reset/
(535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 support.google.com/mail/?p=BadCred... u6-20020a056870304600b000eba1ab2e02sm4002395oau.18 - gsmtp')
Hi, Thanks for reading.
Check if you have turned on less secure apps on your Google account myaccount.google.com/lesssecureapps
and also make sure you have put the correct credentials in your settings.
I have turned on the less secure on my google account, so I'm sure about it. However, I didn't change anything inside the setting. I just want to run your app. Should I change something in the setting part in the following commands?
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = str(os.getenv('EMAIL_USER'))
EMAIL_HOST_PASSWORD = str(os.getenv('EMAIL_PASSWORD'))
You have to include your email credentials in your environment variable.
Hello! I don't think it's possible to send email to users through a Google account anymore. I saw this warning message from Google as I tried to set up an app password: "To help keep your account secure, from May 30, 2022, Google no longer supports the use of third-party apps or devices which ask you to sign in to your Google Account using only your username and password."
Hey Andrew, Thanks for the feedback and you are right. I will update my article.
Hi, thanks for the tutorial, I've followed the previous ones and helped me a lot!
I want to specify some things:
1) I think you've an error in the password_reset_subject template, you created it with a .txt extension instead of .html. Or is there something I'm misunderstanding?
2) It would be awesome if you can create a tutorial about Custom User models, how to create them, how to use them, how to use email instead of username for authentication. I've had a lot of problems with that, I'm new in Django and still struggling.
3) Can you tell me please how did you learn Python+Django? I mean, resources, guidelines and topic plan or something. I used Free code camp tutorials, also a book called Django for Beginners, but I still feel that I just know a litttle bit, there are a lot of things that I've never read/heard about and I don't know if it is part of the process of learning or what. Anyway it feels frustrating.
Thanks again
Hey, thanks for the feedback. Glad I could help.
It's not an error. The subject of the email can be created with a .txt extension as mentioned here in the doc
I'll try to write about those topics. If you want a demo of authentication using email instead of username, you can find here. You can also contact me about the problems you have faced.
Don't get frustrated. I know the feeling :) What worked for me is, once you know the basics, move to doing projects on your own without following a tutorial on youtube. Instead use Google, docs, StackOverflow and blogs to solve a problem during your project. Good luck!
Thanks again, I will take your tips into account
I encountered this error:
Exception Type: TemplateDoesNotExist
Exception Value: password_reset_email.html
and from your article there was no template set for 'password_reset_email.html', any assistance will be appreciated. @earthcomfy
Hi.
password_reset_email.html
file already exists in the article. I think you missed it. Here it is:password_reset_email.html
If you encounter any issues throughout the tutorial, you can check out the code in the GitHub repository
what I mean is your urls.py but I've sorted that out.
I'm getting an error
TemplateDoesNotExist
forusers/password_reset_subject
When entering a valid email but does go through to the "we'll send you reset email" message bit if the email address does not belong to a user. No email is created or a password reset link is created for a valid email as far as I can see.
I've verified that my email configs in the settings file are fine by sending from the manage.py shell using the EmailMessage module.
Any idea why?
Turns out there was a typo in the tutorial
subject_template_name = 'users/password_reset_subject'
should be:
subject_template_name = 'users/password_reset_subject.txt'
Went through a lot of headache trying to figure that one out.
I am getting below error: Environment:
Request Method: POST
Request URL: 127.0.0.1:8000/password_reset/
Django Version: 4.1.13
Python Version: 3.10.12
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'upload_file_app',
'tailwind',
'theme',
'django_browser_reload']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django_browser_reload.middleware.BrowserReloadMiddleware']
Traceback (most recent call last):
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/djongo/cursor.py", line 51, in execute
self.result = Query(
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/djongo/sql2mongo/query.py", line 783, in init
self.query = self.parse()
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/djongo/sql2mongo/query.py", line 875, in parse
raise e
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/djongo/sql2mongo/query.py", line 856, in parse
return handler(self, statement)
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/djongo/sql2mongo/query.py", line 932, in _select
return SelectQuery(self.db, self.connection_properties, sm, self._params)
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/djongo/sql2mongo/query.py", line 116, in __init_
super().init(*args)
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/djongo/sql2mongo/query.py", line 62, in init
self.parse()
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/djongo/sql2mongo/query.py", line 152, in parse
self.where = WhereConverter(self, statement)
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/djongo/sql2mongo/converters.py", line 27, in init
self.parse()
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/djongo/sql2mongo/converters.py", line 119, in parse
self.op = WhereOp(
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/djongo/sql2mongo/operators.py", line 476, in init
self.evaluate()
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/djongo/sql2mongo/operators.py", line 465, in evaluate
op.evaluate()
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/djongo/sql2mongo/operators.py", line 465, in evaluate
op.evaluate()
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/djongo/sql2mongo/operators.py", line 279, in evaluate
raise SQLDecodeError
The above exception (
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/djongo/cursor.py", line 59, in execute
raise db_exe from e
The above exception () was the direct cause of the following exception:
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/core/handlers/exception.py", line 56, in inner
response = get_response(request)
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in get_response
response = wrapped_callback(request, callback_args, **callback_kwargs)
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/views/generic/base.py", line 103, in view
return self.dispatch(request, *args, **kwargs)
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/utils/decorators.py", line 46, in _wrapper
return bound_method(*args, **kwargs)
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/utils/decorators.py", line 134, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/contrib/auth/views.py", line 242, in dispatch
return super().dispatch(*args, **kwargs)
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/views/generic/base.py", line 142, in dispatch
return handler(request, *args, **kwargs)
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/views/generic/edit.py", line 153, in post
return self.form_valid(form)
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/contrib/messages/views.py", line 12, in form_valid
response = super().form_valid(form)
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/contrib/auth/views.py", line 255, in form_valid
form.save(*opts)
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/contrib/auth/forms.py", line 339, in save
for user in self.get_users(email):
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/contrib/auth/forms.py", line 308, in get_users
return (
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/db/models/query.py", line 394, in __iter_
self.fetch_all()
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/db/models/query.py", line 1867, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/db/models/query.py", line 87, in __iter_
results = compiler.execute_sql(
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1398, in execute_sql
cursor.execute(sql, params)
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/db/backends/utils.py", line 102, in execute
return super().execute(sql, params)
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/db/backends/utils.py", line 67, in execute
return self.execute_with_wrappers(
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute
with self.db.wrap_database_errors:
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit_
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
File "/home/mohanrajjj/.local/lib/python3.10/site-packages/djongo/cursor.py", line 59, in execute
raise db_exe from e
Exception Type: DatabaseError at /password_reset/
Exception Value:
Its weird, I cannot get Django to use the templates im passing on the class view, I can do it for log in and password change, but not reset password
Hi. Can I see your code and the error you are getting?
I actually was able to make it show up with a bit of a different approach, it did not like the templates being called 'registration/...' that was an oversight
Hi, I have followed the steps for password reset and i am not getting any errors.
I have entered my email and the app password in the setting part where we setup email.
I have enabled 2factor authentication.
When i enter the email for resetting the password it redirects to the homepage but i am not receiving any mail,not even in spam folder.
There are no errors showing and the message that "the mail is sent" is not showing and it redirects to homepage.
The app loads properly with no errors
Hana Please help.
I am not sure what the instructions on google mean that i should replace my password with the 16 digit code i generated
If this means using it on my environment variable then i have done it but I am not getting the email to recover password
the app loads nicely with no errors
can i get more guidance on how to set up the email generation
I am trying to implement the same but for some reason when I enter the password-reset url, it is asking me to login and the whole process won't happen untill and unless I login.
because dont redirect password_reset_complete???
le mail est envoyé mais si je clique LE LIEN ON ME DIT :
Ce site est inaccessible
127.0.0.1 n'autorise pas la connexion
ERR_CONNECTION_REFUSED