Try   HackMD

Тема 9. Изменение и сброс пароля

https://github.com/roman-yatsenko/django-topics/tree/main/news

Изменение пароля

python manage.py runserver # http://127.0.0.1:8000/users/password_change/
touch templates/registration/password_change_form.html
touch templates/registration/password_change_done.html

templates\registration\password_change_form.html

{% extends 'base.html' %} {% block title %}Password Change{% endblock %} {% block content %} <h1>Password change</h1> <p>Please enter your old password, for security's sake, and then enter your new password twice so we can verify you typed it in correctly.</p> <form method="POST"> {% csrf_token %} {{ form.as_p }} <input class="btn btn-success" type="submit" value="Change my password"> </form> {% endblock %}
python manage.py runserver

templates\registration\password_change_done.html

{% extends 'base.html' %} {% block title %}Password Change Successful{% endblock %} {% block content %} <h1>Password change successful</h1> <p>Your password was changed.</p> {% endblock content %}

Сброс пароля

news_project\settings.py

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
python manage.py runserver # http://127.0.0.1:8000/users/password_reset/

Собственные шаблоны

touch templates/registration/password_reset_form.html touch templates/registration/password_reset_done.html touch templates/registration/password_reset_confirm.html touch templates/registration/password_reset_complete.html

templates\registration\password_reset_form.html

{% extends 'base.html' %} {% block title %}Forgot Your Password?{% endblock %} {% block content %} <h1>Forgot your password?</h1> <p>Enter your email address below, and we'll email instructions for setting a new one.</p> <form method="POST"> {% csrf_token %} {{ form.as_p }} <input class="btn btn-success" type="submit" value="Send me instructions!"> </form> {% endblock %}

templates\registration\password_reset_done.html

{% extends 'base.html' %} {% block title %}Email Sent{% endblock %} {% block content %} <h1>Check your inbox.</h1> <p>We've emailed you instructions for setting your password. You should receive the email shortly!</p> {% endblock %}
python manage.py runserver # http://127.0.0.1:8000/users/password_reset/

templates\registration\password_reset_confirm.html

{% extends 'base.html' %} {% block title %}Enter new password{% endblock %} {% block content %} <h1>Set a new password!</h1> <form method="POST"> {% csrf_token %} {{ form.as_p }} <input class="btn btn-success" type="submit" value="Change my password"> </form> {% endblock %}

templates\registration\password_reset_complete.html

{% extends 'base.html' %} {% block title %}Password reset complete{% endblock %} {% block content %} <h1>Password reset complete</h1> <p> Your new password has been set. You can log in now on the <a href="{% url 'login' %}">log in page</a>. </p> {% endblock %}

SendGrid

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Регистрация с настоящей почтой, отличной от администратора сайта

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.sendgrid.net' EMAIL_HOST_USER = 'sendgrid_username' EMAIL_HOST_PASSWORD = 'sendgrid_password' EMAIL_PORT = 587 EMAIL_USE_TLS = True

© Яценко Р.Н., 2021

Учебный центр компьютерных технологий "Кит"

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →