Reputation: 673
I want to make my own site to log in django 1.7. But when I get logs will be taken to a page to sign in and get a message that there is no such user. My user is in the database.
VIEW
def my_login(request):
if request.method == 'POST':
username = request.POST.get('username', '')
password = request.POST.get('password', '')
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
return HttpResponseRedirect('/')
else:
print "User does not exist"
return render_to_response('tests/login1.html', context_instance=RequestContext(request))
TEMPLATE
<form class="form-horizontal" name="LoginForm" action="./" method="post">
{% csrf_token %}
<div class="control-group">
<label class="control-label" for="username">Username</label>
<div class="controls">
<input type="text" id="username" value="" placeholder="Username">
</div>
</div>
<div class="control-group">
<label class="control-label" for="password">Password</label>
<div class="controls">
<input type="password" name="password" value="" id="password" placeholder="Password">
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn">Login</button>
</div>
</div>
</form>
Upvotes: 1
Views: 556
Reputation: 59164
You are not sending the username
to the view because the name
attribute is missing in your input
tag. Instead of:
<input type="text" id="username" value="" placeholder="Username">
try this:
<input type="text" name="username" id="username" value="" placeholder="Username">
Upvotes: 3