Witam mam problem z wyrzucaniem wyjatkow w Django moj kod:
from django import forms
from .models import User
from django.forms import ValidationError
class UserForm(forms.Form):
username = forms.CharField(label="username",max_length=100,min_length=8)
email = forms.EmailField(label="email")
password = forms.CharField(widget=forms.PasswordInput,min_length=8)
def check_if_user_exists(self,username):
if(User.objects.all().filter(username__icontains=username).exists()):
raise ValidationError('The user with this username already exists!')
return False
from django.shortcuts import render, redirect
from .forms import UserForm
from .models import User
def index(request):
user = User()
if request.method == 'POST':
form = UserForm(request.POST)
if form.is_valid() :
user.username = form.cleaned_data['username']
user.email = form.cleaned_data['email']
user.password = hash(form.cleaned_data['password'])
if form.check_if_user_exists(user.username):
pass
else:
user.save()
return redirect('/register/')
else:
form = UserForm()
return render(request,'registration/index.html',{'form':form})
link z SS bledu : http://imgur.com/a/tVINo