def registration_view(request): form = RegistrationForm(request.POST or None) if form.is_valid(): user = form.save() user.set_password(request.POST['password']) user.save() return redirect('/index/') return render(request, 'accounts/registration.html', {'form': form})
def registration_view(request): context = {} if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): form.save() email = form.cleaned_data.get('email') raw_password = form.cleaned_data.get('password1') account = authenticate(email=email, password=raw_password) login(request, account) return redirect('index') else: context['registration_form'] = form else: form = RegistrationForm() context['registration_form'] = form return render(request, 'accounts/register.html', context)