def register_form(request): if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): form.save() username = form.cleaned_data['username'] password = form.cleaned_data['password1'] user = authenticate(username=username, password=password) login(request, user) current_user = request.user data = UserProfile() data.user_id = current_user.id data.image = "images/users/user.png" data.save() messages.success(request, "Your account has been created") return HttpResponseRedirect('/') else: messages.warning(request, form.errors) return HttpResponseRedirect('/register') form = RegisterForm() context = { 'form': form, } return render(request, 'register_form.html', context)
def register(request): if request.method == 'POST': form = RegisterForm(request.POST, request.FILES) if form.is_valid(): user = form.save(commit=False) user.password = make_password(user.password) user.save() return redirect('/user/login/') else: return render(request, 'register.html', {'error': form.errors}) else: return render(request, 'register.html')