Хочу написать авторизацию пользователя и регистрацию на одной странице, но у меня не получается авторизовать пользователя. В питоновском коде всё вроде правильно, я думаю что проблема где-то в HTML. Прошу помощи у знатоков.
Форма:
<div id="form">
<div class="container">
<div class="col-lg-6 col-lg-offset-3 col-md-6 col-md-offset-3 col-md-8 col-md-offset-2">
<div id="userform">
<ul class="nav nav-tabs nav-justified" role="tablist">
<li class="active"><a href="#signup" role="tab" data-toggle="tab">Регистрация</a></li>
<li><a href="#login" role="tab" data-toggle="tab">Войти</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane fade active in" id="signup">
<h2 class="text-uppercase text-center"> Зарегистрироваться бесплатно</h2>
<form id="signup">
<div class="row">
<div class="col-xs-12 col-sm-6">
<div class="form-group">
<label>Имя<span class="req">*</span> </label>
<input type="text" class="form-control" id="first_name" required data-validation-required-message="Please enter your name." autocomplete="off">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="col-xs-12 col-sm-6">
<div class="form-group">
<label> Фамилия <span class="req">*</span> </label>
<input type="text" class="form-control" id="last_name" required data-validation-required-message="Please enter your name." autocomplete="off">
<p class="help-block text-danger"></p>
</div>
</div>
</div>
<div class="form-group">
<label> Email<span class="req">*</span> </label>
<input type="email" class="form-control" id="email" required data-validation-required-message="Please enter your email address." autocomplete="off">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<label> Номер телефона<span class="req">*</span> </label>
<input type="tel" class="form-control" id="phone" required data-validation-required-message="Please enter your phone number." autocomplete="off">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<label> Пароль<span class="req">*</span> </label>
<input type="password" class="form-control" id="password" required data-validation-required-message="Please enter your password" autocomplete="off">
<p class="help-block text-danger"></p>
</div>
<div class="mrgn-30-top">
<button type="submit" name="signup" class="btn btn-larger btn-block"/>
Зарегистрироваться
</button>
</div>
</form>
</div>
<div class="tab-pane fade in" id="login">
<h2 class="text-uppercase text-center"> Войти</h2>
<form id="login">
<div class="form-group">
<label> Email<span class="req">*</span> </label>
<input type="username" class="form-control" id="email" required data-validation-required-message="Please enter your email address." autocomplete="off">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<label> Пароль<span class="req">*</span> </label>
<input type="password" class="form-control" id="password" required data-validation-required-message="Please enter your password" autocomplete="off">
<p class="help-block text-danger"></p>
</div>
<div class="mrgn-30-top">
{% csrf_token %}
<button type="submit" name="submit" value="login" action="{% url 'home' %}" formmethod="post" method="post" class="btn btn-larger btn-block"/>
Войти
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- /.container -->
</div>
Код:
def user_login(request):
if request.method == 'POST':
if request.POST.get('submit') == 'login':
# return HttpResponse(request.POST.items())
# print(request.POST['username'], request.POST['password'])
username = request.POST['username']
password = request.POST['password']
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
return HttpResponse('logining')
return HttpResponse('error')
elif request.POST.get('submit') == 'signup':
pass
elif request.method == 'GET':
return render(request, 'pizza/sign_up.html')