Не могу разместить вход и регистрацию на одном html шаблоне.
Пытался сделать это так:
class LoginRegisterView(View):
template_name = 'entrants/reg.html'
def get(self, request):
login_form = AuthenticationForm()
registration_form = UserCreationForm()
return render(request, self.template_name, {'login_form': login_form, 'registration_form': registration_form})
def post(self, request):
if 'login_submit' in request.POST:
login_form = AuthenticationForm(request, request.POST)
if login_form.is_valid():
user = login_form.get_user()
login(request, user)
return redirect('profile') # Замените 'home' на URL вашей домашней страницы
else:
registration_form = UserCreationForm(request.POST)
elif 'register_submit' in request.POST:
registration_form = UserCreationForm(request.POST)
if registration_form.is_valid():
user = registration_form.save()
login(request, user)
return redirect('reg') # Замените 'home' на URL вашей домашней страницы
else:
login_form = AuthenticationForm(request, request.POST)
else:
login_form = AuthenticationForm()
registration_form = UserCreationForm()
return render(request, self.template_name, {'login_form': login_form, 'registration_form': registration_form})