while trying to check the (this form) link i got http://127.0.0.1:8000/3/password/ instead of http://127.0.0.1:8000/members/password/ in UpdateView,UserChangeForm.
UserChangeForm image:
Code for UserChangeForm and PasswordChangeForm
urls.py in Project Directary
from django.contrib import admin
from django.urls import path,includeurlpatterns = [
path(‘admin/’, admin.site.urls),
path(‘’,include(‘blogpost.urls’)),
path(‘members/’,include(‘django.contrib.auth.urls’)),
path(‘members/’,include(‘members.urls’)),]
form.py in Application Directary
from typing import Any
from django.contrib.auth.forms import UserCreationForm,UserChangeForm
from django.contrib.auth.models import User
from django import formsclass SignUpForm(UserCreationForm):
email = forms.EmailField(widget=forms.EmailInput(attrs={‘class’:‘form-control’}))
first_name = forms.CharField(max_length=100,widget=forms.TextInput(attrs={‘class’:‘form-control’}))
last_name = forms.CharField(max_length=100,widget=forms.TextInput(attrs={‘class’:‘form-control’}))class Meta: model = User fields = ('username','first_name','last_name','email','password1','password2') def __init__(self, *args, **kwargs): super(SignUpForm,self).__init__(*args, **kwargs) self.fields['username'].widget.attrs['class'] = 'form-control' self.fields['password1'].widget.attrs['class'] = 'form-control' self.fields['password2'].widget.attrs['class'] = 'form-control'
class EditProfileForm(UserChangeForm):
email = forms.EmailField(widget=forms.EmailInput(attrs={‘class’:‘form-control’}))
first_name = forms.CharField(max_length=100,widget=forms.TextInput(attrs={‘class’:‘form-control’}))
last_name = forms.CharField(max_length=100,widget=forms.TextInput(attrs={‘class’:‘form-control’}))
username = forms.CharField(max_length=100,widget=forms.TextInput(attrs={‘class’:‘form-control’}))
last_login = forms.CharField(max_length=100,widget=forms.TextInput(attrs={‘class’:‘form-control’}))
is_superuser = forms.CharField(max_length=100,widget=forms.CheckboxInput(attrs={‘class’:‘form-check’}))
is_staff = forms.CharField(max_length=100,widget=forms.CheckboxInput(attrs={‘class’:‘form-check’}))
is_active = forms.CharField(max_length=100,widget=forms.CheckboxInput(attrs={‘class’:‘form-check’}))
date_joined = forms.CharField(max_length=100,widget=forms.TextInput(attrs={‘class’:‘form-control’}))class Meta: model = User fields = ('username','first_name','last_name','email','last_login','is_superuser','is_staff','is_active','date_joined')
views.py
from django.shortcuts import render
from django.views import generic
from django.urls import reverse_lazy
from .forms import SignUpForm,EditProfileFormclass UserRegisterView(generic.CreateView):
form_class = SignUpForm
template_name = ‘registration/register.html’
success_url = reverse_lazy(‘login’)class UserEditView(generic.UpdateView):
form_class = EditProfileForm
template_name = ‘registration/edit_profile.html’
success_url = reverse_lazy(‘Home’)def get_object(self): return self.request.user
urls.py
from django.urls import path
from .views import UserRegisterView, UserEditView
from django.contrib.auth import views as auth_viewsurlpatterns = [
path('register/', UserRegisterView.as_view(), name='register'), path('edit_profile/', UserEditView.as_view(), name='Edit-Profile'), path('password/', auth_views.PasswordChangeView.as_view(), name='password'),
]
while check the link this was the output:
3/password/