Django password reset. Do not send mail

I am trying to get django reset password, but reset is not sent.

I know that my email is set up correctly, because the following works both in the shell and in one of my views (I use it to receive support email for myself).

from django.core.mail import send_mail send_mail('Subject here', 'Here is the message.', ' admin@mydomain.com ',[' me@gmail.com '], fail_silently=False) 

I can go to my password submission reset ( password / reset / ), and after I send it by email, it will redirect me to the password / reset / done / correctly, but it does not send the email.

Here is my urls.py :

 (r'^password/reset/$','django.contrib.auth.views.password_reset'), (r'^password/reset/done/$','django.contrib.auth.views.password_reset_done'), (r'^password/reset/confirm/$','django.contrib.auth.views.password_reset_confirm'), (r'^password/reset/complete/$','django.contrib.auth.views.password_reset_confirm'), (r'^password/change/$','django.contrib.auth.views.password_change'), (r'^password/change/done/$','django.contrib.auth.views.password_change_done'), 

Here is my password_reset_form.html :

 <html> <head> <link rel="stylesheet" type="text/css" href="/media/css/style_login.css" /> <title>Información de acceso requerida</title> </head> <body> <div id="wrapper"> <h1>Recuperar password</h1> <p>Utilice este formulario cuando desee recuperar el password para su usuario.</p> {% if form.errors %} <p>No hay un usuario registrado con ese correo electronico.</p> {% endif %} <form method="post" action="{% url django.contrib.auth.views.password_reset_done %}"> {% csrf_token %} {{ form }} <input class="login" type="submit" value="Recuperar" /> </form> </div> </body> 

Any ideas? Thanks

+6
source share
2 answers

I should mention that I use hostgator as my provider. These are my .py settings

 EMAIL_HOST = 'my-domain.com' EMAIL_HOST_PASSWORD = 'my cpanel password' EMAIL_HOST_USER = 'my cpanel user' EMAIL_PORT = 25 EMAIL_USE_TLS = False DEFAULT_FROM_EMAIL = ' webmaster@my-host.com ' SERVER_EMAIL = ' root@my-domain.com ' 

The above settings work!

+7
source

In my case, I created users using create_user() . My idea was to create a bunch of accounts and then tell people that they can go to the reset password form to set their password. I think it sucks if you need to tell them "Use the password" welcome123 "and then remember to change your password" or so.

I found out if I didn’t pass Password='foo' , and also, if I passed Password=None before create_user() , a password reset is not sent. This is because Django sometimes uses an empty password to know that it does not need to be authenticated locally, but rather uses LDAP or such.

So now I do this:

 User.objects.create_user( user_name, email=user_email, password=os.urandom(32), ) 

And I can direct people to use the reset password function for their new accounts. I think it would be great if I had an option in create_user to automatically send an email to activate an account for users!

+3
source

Source: https://habr.com/ru/post/904350/


All Articles