Your Ad Here

Tuesday, January 17, 2012

Having Headache With LoginForm

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 django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 comments:

Post a Comment