def registration_view(request): form = RegistrationForm(request.POST or None) categories = Category.objects.all() # проверка формы на валидность if form.is_valid(): new_user = form.save( commit=False ) # эта строчка необходима когда форма создается на основе модели # все что внутри до new_user.save() Относится к данным из формы # получение данных из формы username = form.cleaned_data['username'] password = form.cleaned_data['password'] email = form.cleaned_data['email'] first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] # создание пользователя на основе полученных данных new_user.username = username new_user.set_password(password) new_user.first_name = first_name new_user.last_name = last_name new_user.email = email new_user.save( ) # эта строчка необходима когда форма создается на основе модели login_user = authenticate(username=username, password=password) if login_user: login(request, login_user) return HttpResponseRedirect(reverse('base')) context = {'form': form, 'categories': categories} return render(request, 'registration.html', context)
def registration_view(request): form = RegistrationForm(request.POST or None) categories = Category.objects.all() if form.is_valid(): new_user = form.save(commit=False) username = form.cleaned_data['username'] password = form.cleaned_data['password'] email = form.cleaned_data['email'] first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] new_user.username = username new_user.set_password(password) new_user.first_name = first_name new_user.last_name = last_name new_user.email = email new_user.save() login_user = authenticate(username=username, password=password) if login_user: login(request, login_user) return HttpResponseRedirect(reverse('base')) context = { 'form': form, 'categories':categories } return render(request, 'registration.html', context)
def registration_view(request): categories = Category.objects.all() form = RegistrationForm(request.POST or None) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('base')) context = {'form': form, 'categories': categories} return render(request, 'registration.html', context)
def registration_view(request): form = RegistrationForm(request.POST or None) categories = Category.objects.all() if form.is_valid(): new_user = form.save(commit=False) username = form.cleaned_data["username"] password = form.cleaned_data["password"] email = form.cleaned_data["email"] first_name = form.cleaned_data["first_name"] last_name = form.cleaned_data["last_name"] new_user.username = username new_user.set_password(password) new_user.first_name = first_name new_user.last_name = last_name new_user.email = email new_user.save() login_user = authenticate(username=username, password=password) if login_user: login(request, login_user) return HttpResponseRedirect(reverse("base")) context = {"form": form, "categories": categories} return render(request, "signup.html", context)
def registration_view(request): form = RegistrationForm(request.POST or None) if form.is_valid(): return HttpResponseRedirect(reverse('base')) context = {'form': form} return render(request, 'registration.html', context)