With using
@login_required decorator the user needs to be logged in to allow execution,
don't makes much sense for a login :P
Am 17.01.2012 22:23, schrieb coded kid:
Hi guys, I’m having problem with my login form. The login form will
redirect me to the next page even if I didn’t input anything in the
username and password field. Also it can’t get the username of the
registered users to verify if the user data is wrong or right. How can
I get rid of this problem?
Below are my code:
In views.py
from django.db import models
from mymeek.meekme.models import RegisterForm
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.template import RequestContext
from django.http import HttpResponseRedirect
from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required
@login_required
def mylogin(request):
if request.method=='POST':
username= request.POST['username']
password= request.POST['password']
user=authenticate (username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
return HttpResponseRedirect('/logpage/')
else:
return direct_to_template(request,'q_error.html')
else:
return render_to_response('mainpage.html')
In my template:
<html>
<form action='' method="post">
<table>
<tr>
<td>{{form.username.label_tag}}</td>
<td>{{form.username}}</td>
</tr>
<tr>
<td>{{form.password.label_tag}}</td>
<td>{{form.password}}</td>
</tr>
</table>
<input type="submit" value="Login" />
</form>
</html>
Please help me out! Thanks.
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.