merhaba.djangoda register form.yapiyordum.ama forms.py ye password2 alani eklememe ragmen password2 alani gozukmuyor.yani urli yazib registere gistdigimizde sadece password1 gozukuyor:
views.py:
def register_view(request):
form = loginform(request.POST or None)
if form.is_valid():
user = form.save(commit = False)
#username = form.cleaned_data.get('username')
password = form.cleaned_data.get('password1')
user.set_password(password)
user.save()
new_user = authenticate(username = user.username,password = password)
login(request,new_user)
return redirect('base')
return render(request,'logintemp.html',{'form':form,'title':'Qeydiyyatdan Kec'})
forms.py:
class registerform(forms.ModelForm):
username = forms.CharField(max_length=100,label='Adiniz')
password1 = forms.CharField(max_length=20,widget=forms.PasswordInput,label='Sifreniz')
password2 = forms.CharField(max_length=20,widget=forms.PasswordInput,label='Sifreniz(Tekrar)')
class Meta:
model = User
fields = [
'username',
'password1',
'password2',
]
def clean_password2(self):
password1 = self.cleaned_data.get('password1')
password2 = self.cleaned_data.get('password2')
if password1 and password2 and password1 != password2:
raise forms.ValidationError('sifreler eyni deyil')
return password2
template:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
<div class="container">
<div class="row">
<div class="col-md-7 col-md-offset-3">
<form method="POST">
{% csrf_token %}
<div class="form-group">
<h1 class="formyazisi">{{ title }}</h1>
{{form.as_p}}
<button type="submit" class="btn btn-outline-success">{{ title }}</button>
</div>
</form>
</div>
</div>
</div>
yardimci olursaniz sevinirim.