Configure Django admin password change page

I would like to have my own change_password page, and I already use the admin login from Django (using from django.contrib.auth.decorators import login_required ).
Got admin input, but would like to change the change_password page.

How to do it?
I am not sure how to refer to the administrator login, or because I want to configure my change_password, should I also configure my administrator login?

Need to be guided. Thanks...

+4
source share
2 answers

You can import forms

from django.contrib.auth.views import password_change

If you look at the Django password_change view. You will notice that it accepts the viewing options that you can provide in order to customize the presentation to your own needs, thereby making your website drier.

 def password_change(request, template_name='registration/password_change_form.html', post_change_redirect=None, password_change_form=PasswordChangeForm, current_app=None, extra_context=None): if post_change_redirect is None: post_change_redirect = reverse('django.contrib.auth.views.password_change_done') if request.method == "POST": form = password_change_form(user=request.user, data=request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(post_change_redirect) else: form = password_change_form(user=request.user) context = { 'form': form, } if extra_context is not None: context.update(extra_context) return TemplateResponse(request, template_name, context, current_app=current_app) 

In particular, template_name and extra_context to make your view look like

 from django.contrib.auth.views import password_change def my_password_change(request) return password_change(template_name='my_template.html', extra_context={'my_var1': my_var1}) 
+8
source

Searching for Django templates allows you to override any template, in the folder of your template just add the administrator templates that you want to override, for example:

 templates/ admin/ registration/ password_change_form.html password_reset_complete.html password_reset_confirm.html password_reset_done.html password_reset_email.html password_reset_form.html 
+3
source

All Articles