Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django password change view form

I'm still new to Django and have a few questions on how using built in views work. I noticed that djang comes with a built in password change view at django.contrib.auth.views.password_change. This view shows the admin site in the background of the template, while I want to provide my own css/template but keep the form and functionality of that view. How would I do this? Can you pass something into the urls.py

r'password_change/$', 'django.contrib.auth.views.password_change')

like a custom template? I am unsure of the proper way to do this.

like image 236
user1835351 Avatar asked Dec 04 '12 20:12

user1835351


People also ask

How can I see my password in Django?

In order to use the built-in Django check_password() function, we need to import it, which is shown in the first line of code. So the current password of the user is, request. user. password, which we store in the currentpassword variable.

How do I change my Django admin password?

manage.py changepassword *username* offers a method of changing a user's password from the command line. It prompts you to change the password of a given user which you must enter twice. If they both match, the new password will be changed immediately.

What is Auth_user_model in Django?

Django allows you to override the default user model by providing a value for the AUTH_USER_MODEL setting that references a custom model. Method 2 – AUTH_USER_MODEL : AUTH_USER_MODEL is the recommended approach when referring to a user model in a models.py file.

What is UserCreationForm in Django?

Django UserCreationForm is used for creating a new user that can use our web application. It has three fields: username, password1, and password2(which is basically used for password confirmation). To use the UserCreationForm, we need to import it from django. contrib. auth.


2 Answers

You can specify the template that should be used by setting the template_name argument:

(r'password_change/$', 'django.contrib.auth.views.password_change', {'template_name': 'path/to/password_reset.html'})

In your template make sure you use the provided {{ form }} template variable and you're good to go.

like image 193
ptrck Avatar answered Sep 17 '22 23:09

ptrck


Django will attempt to load templates first from your application, then fall back. So, to override the templates for contrib.auth, you just need to:

  1. Create a directory named auth in your template directory.
  2. Create a template of the same name that the built-in view is expecting to load.
  3. There is no step 3.
like image 29
Brandon Avatar answered Sep 19 '22 23:09

Brandon