--- tags: Python Web source: Django 2.0 для начинающих, Глава 11-12, с.232 --- # Тема 9. Изменение и сброс пароля https://github.com/roman-yatsenko/django-topics/tree/main/news ## Изменение пароля ```shell= python manage.py runserver # http://127.0.0.1:8000/users/password_change/ ``` ```shell touch templates/registration/password_change_form.html touch templates/registration/password_change_done.html ``` ### `templates\registration\password_change_form.html` ```htmlmixed= {% 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 %} ``` ```shell= python manage.py runserver ``` ### `templates\registration\password_change_done.html` ```htmlmixed= {% 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` ```python=137 EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' ``` ```shell= python manage.py runserver # http://127.0.0.1:8000/users/password_reset/ ``` ## Собственные шаблоны ```shell= 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` ```htmlmixed= {% 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` ```htmlmixed= {% 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 %} ``` ```shell= python manage.py runserver # http://127.0.0.1:8000/users/password_reset/ ``` ### `templates\registration\password_reset_confirm.html` ```htmlmixed= {% 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` ```htmlmixed= {% 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 <!-- Глава 12, не работает smtp в Django --> :arrow_right: Регистрация с настоящей почтой, отличной от администратора сайта ```python=137 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 ``` --- (c) Яценко Р.Н., 2021 [Учебный центр компьютерных технологий "Кит"](http://kit.kh.ua/) <img src="https://i.imgur.com/Kh901c1.png" style="width: 150px; position: fixed; top: 100px; right: 10px; border: 0; box-shadow: none;">
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up