def sign_up(request): if request.method == 'POST': form = SignupForm(request.POST) if form.is_valid(): user = form.save() # Log-in the user right away, then redirect home messages.success(request, 'Account created successfully. Welcome!') login(request, user) return redirect('home') else: form = SignupForm() context = { 'form': form, } return render(request, 'accounts/signup.html', context)
def post(self, request): if request.method == "POST": form = SignupForm(request.POST) if form.is_valid(): user = form.save(commit=False) print(form.cleaned_data) username = form.cleaned_data["username"] raw_password = form.cleaned_data["password1"] user.save() user = authenticate(username=username, password=raw_password) if user: login(request, user) return redirect("success") else: print(form.errors) return render(request, self.template_name, {"form": form}) else: return render(request, self.template_name, {"form": self.form})
def sign_up(request): if request.method == 'POST': form = SignupForm(request.POST) if form.is_valid(): user = form.save(commit=False) password = forms.CharField(widget=forms.PasswordInput) user.set_password(form.cleaned_data['password']) user.save() # Log-in the user right away messages.success(request, 'Account created successfully. Welcome!') login(request, user) return redirect('/') else: form = SignupForm() context = { 'form': form, } return render(request, 'accounts/signup.html', context)