标签:change success links astyle you doc img text load
@sensitive_post_parameters() @csrf_protect @login_required @deprecate_current_app def password_change(request, template_name=‘registration/password_change_form.html‘, post_change_redirect=None, password_change_form=PasswordChangeForm, extra_context=None): warnings.warn("The password_change() view is superseded by the " "class-based PasswordChangeView().", RemovedInDjango21Warning, stacklevel=2) if post_change_redirect is None: post_change_redirect = reverse(‘password_change_done‘) else: post_change_redirect = resolve_url(post_change_redirect) if request.method == "POST": form = password_change_form(user=request.user, data=request.POST) if form.is_valid(): form.save() # Updating the password logs out all other sessions for the user # except the current one. update_session_auth_hash(request, form.user) return HttpResponseRedirect(post_change_redirect) else: form = password_change_form(user=request.user) context = { ‘form‘: form, ‘title‘: _(‘Password change‘), } if extra_context is not None: context.update(extra_context) return TemplateResponse(request, template_name, context) @login_required @deprecate_current_app def password_change_done(request, template_name=‘registration/password_change_done.html‘, extra_context=None): warnings.warn("The password_change_done() view is superseded by the " "class-based PasswordChangeDoneView().", RemovedInDjango21Warning, stacklevel=2) context = { ‘title‘: _(‘Password change successful‘), } if extra_context is not None: context.update(extra_context) return TemplateResponse(request, template_name, context)
from django.conf.urls import url from . import views from django.contrib.auth import views as auth_view urlpatterns = [ url(r‘^login$‘,views.user_login,name="user_login"), url(r‘^new_login$‘,auth_view.login,{ "template_name":"account/registration/login.html"},name="new_user_login"), url(r‘^logout/$‘,auth_view.logout,{ "template_name":"account/logout.html"},name="user_logout"), url(r‘^register/$‘,views.register,name="user_register"), url(r‘^password_change/$‘,auth_view.password_change,{"post_change_redirect":"/account/password_change_done/","template_name":"account/password_change_form.html"},name="password_change"), url(r‘^password_change_done/$‘,auth_view.password_change_done,{"template_name":"account/password_change_done.html"},name="password_change_done"), ]
templates/account/password_change_form.html 内容如下:(PS:其实用的是 django自带的 /usr/local/python3/lib/python3.6/site-packages/django/contrib/admin/templates/registration ,书里面提供的前端,不会提示密码不合理的地方)
{% extends "admin/base_site.html" %} {% load i18n static %} {% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}" />{% endblock %} {% block userlinks %}{% url ‘django-admindocs-docroot‘ as docsroot %}{% if docsroot %}<a href="{{ docsroot }}">{% trans ‘Documentation‘ %}</a> / {% endif %} {% trans ‘Change password‘ %} / <a href="{% url ‘admin:logout‘ %}">{% trans ‘Log out‘ %}</a>{% endblock %} {% block breadcrumbs %} <div class="breadcrumbs"> <a href="{% url ‘admin:index‘ %}">{% trans ‘Home‘ %}</a> › {% trans ‘Password change‘ %} </div> {% endblock %} {% block title %}{{ title }}{% endblock %} {% block content_title %}<h1>{{ title }}</h1>{% endblock %} {% block content %}<div id="content-main"> <form method="post">{% csrf_token %} <div> {% if form.errors %} <p class="errornote"> {% if form.errors.items|length == 1 %}{% trans "Please correct the error below." %}{% else %}{% trans "Please correct the errors below." %}{% endif %} </p> {% endif %} <p>{% trans "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> <fieldset class="module aligned wide"> <div class="form-row"> {{ form.old_password.errors }} {{ form.old_password.label_tag }} {{ form.old_password }} </div> <div class="form-row"> {{ form.new_password1.errors }} {{ form.new_password1.label_tag }} {{ form.new_password1 }} {% if form.new_password1.help_text %} <div class="help">{{ form.new_password1.help_text|safe }}</div> {% endif %} </div> <div class="form-row"> {{ form.new_password2.errors }} {{ form.new_password2.label_tag }} {{ form.new_password2 }} {% if form.new_password2.help_text %} <div class="help">{{ form.new_password2.help_text|safe }}</div> {% endif %} </div> </fieldset> <div class="submit-row"> <input type="submit" value="{% trans ‘Change my password‘ %}" class="default" /> </div> </div> </form></div> {% endblock %}
templates/account/password_change_done.html 内容如下:
{% extends "base.html" %} {% block title%}password change done {% endblock %} {% block content%} <div class="text-center row vertical-md-sm"> <p>your password was changed</p> </div> {% endblock %}
确认老密码,填写新密码后,点击 change my password,自动跳到完成界面
标签:change success links astyle you doc img text load
原文地址:https://www.cnblogs.com/yaoyuanchun/p/13986441.html