In models.py:
class Login(models.Model):
username=models.CharField(max_length=50)
password=models.CharField(max_length=50)
def __unicode__(self):
return u"%s-%s" % (self.username, self.password)
class LoginForm(ModelForm):
class Meta:
model=Login
fields=('username','password')
in my views.py:
from django.contrib import auth
from django.shortcuts import render_to_response
from django.http import HttpResponse, Http404
from django.template import RequestContext
from django.http import HttpResponseRedirect
def login_view(request):
username=request.POST.get('username', '')
password=request.POST.get('password', '')
user=auth.authenticate(username=username, password=password)
if user is not None and user.is_active:
auth.login(request,user)
return HttpResponseRedirect("/homi/")
else:
return render_to_response('login.html',
{'LoginForm':LoginForm},context_instance=RequestContext(request))
def logout_view(request):
auth.logout(request)
return HttpResponseRedirect("/logme/")
in url.py
from django.contrib.auth.views import login, logout
(r'^accounts/login/$', login_view),
(r'^accounts/logout/$', login_view),
in my template:
{% extends "base_meek.html" %}
{% block body %}
<form action="" method="POST" />
<table>
{{LoginForm}}
</table>
<input type="submit" value="Log In" />
(% endblock %}
After creating all those codes. I tried to login with my password and
username, but if failed! So I added the username and password through
Django admin. So after adding it, I tried to login with with username
and password, it works!
My question is, is that how it's suppose to be? if that's the way it
should be, so it means I will be adding users manually before they can
login? What about other fields like, country, state etc in my
RegisterForm, will it be added automatically??
Am I doing something wrong? Please I need answers because django is
driving me crazy!!!
--
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.
No comments:
Post a Comment