Hi All,
I have created a login screen for users of the site which is like User
Profile and uses the username and password from django users. When i try to
login to my view i get the error below.

Environment: Request Method: POST Request URL:
http://127.0.0.1/commTrack/commtrack/account/login/ Django Version: 1.1
Python Version: 2.5.4 Installed Applications: ['django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.sessions',
'django.contrib.sites', 'django.contrib.admin', 'commTrack.commtrack']
Installed Middleware: ('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware') Traceback: File
"C:\Python25\lib\site-packages\django\core\handlers\base.py" in get_response
92. response = callback(request, *callback_args, **callback_kwargs) File
"C:/xampp/htdocs/commTrack\commtrack\views.py" in login_view 71.
login(request, user) Exception Type: TypeError at /commtrack/account/login/
Exception Value: login() takes exactly 1 argument (2 given)

Here is my setting.py

# Django settings for commTrack project. DEBUG = True TEMPLATE_DEBUG = DEBUG
ADMINS = ( # ('Your Name', 'your_em...@domain.com'), ) MANAGERS = ADMINS
DATABASE_ENGINE = 'mysql' # 'postgresql_psycopg2', 'postgresql', 'mysql',
'sqlite3' or 'oracle'. DATABASE_NAME = 'commtrack' # Or path to database
file if using sqlite3. DATABASE_USER = 'root' # Not used with sqlite3.
DATABASE_PASSWORD = '' # Not used with sqlite3. DATABASE_HOST = 'localhost'
# Set to empty string for localhost. Not used with sqlite3. DATABASE_PORT =
'3306' # Set to empty string for default. Not used with sqlite3. # Local
time zone for this installation. Choices can be found here: #
http://en.wikipedia.org/wiki/List_of_tz_zones_by_name # although not all
choices may be available on all operating systems. # If running in a Windows
environment this must be set to the same as your # system time zone.
#TIME_ZONE = 'Africa/Dar_es_Salaam' TIME_ZONE = 'America/Chicago' # Language
code for this installation. All choices can be found here: #
http://www.i18nguy.com/unicode/language-identifiers.html LANGUAGE_CODE =
'en-us' SITE_ID = 1 # If you set this to False, Django will make some
optimizations so as not # to load the internationalization machinery.
USE_I18N = True # Absolute path to the directory that holds media. #
Example: "/home/media/media.lawrence.com/" MEDIA_ROOT =
"C:/xampp/htdocs/commTrack/media/" # URL that handles the media served from
MEDIA_ROOT. Make sure to use a # trailing slash if there is a path component
(optional in other cases). # Examples: "http://media.lawrence.com";, "
http://example.com/media/"; MEDIA_URL = "http://127.0.0.1/commTrack/media/"; #
URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash. # Examples: "http://foo.com/media/";, "/media/".
ADMIN_MEDIA_PREFIX = "http://localhost/commTrack/media/"; # Make this unique,
and don't share it with anybody. SECRET_KEY =
'i##+%y9+1u$vd#!g$=qld(--(nb-b71czx4cill&n!+1%2)er=' # List of callables
that know how to import templates from various sources. TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source', #
'django.template.loaders.eggs.load_template_source', ) MIDDLEWARE_CLASSES =
( 'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware', ) ROOT_URLCONF =
'commTrack.urls' TEMPLATE_DIRS = ( # Put strings here, like
"/home/html/django_templates" or "C:/www/django/templates". # Always use
forward slashes, even on Windows. # Don't forget to use absolute paths, not
relative paths. #"/media/Otoro/Projects ITIDO/mytemplates"
"C:/xampp/htdocs/commTrack/templates/", ) INSTALLED_APPS = (
'django.contrib.auth', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin',
'commTrack.commtrack', ) AUTHENTICATION_BACKENDS = (
'commTrack.commtrack.models.CustomUserModelBackend', ) CUSTOM_USER_MODEL =
'commtrack.CustomUser'


Here is my view for login


from django.contrib.auth import authenticate, login
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from commTrack.commtrack.models import *

def login_view(request): username = request.POST.get('username', '')
password = request.POST.get('password', '') user =
authenticate(username=username, password=password) if user is not None and
user.is_active: # Correct password, and the user is marked "active"
login(request, user) # Redirect to a success page. return
HttpResponseRedirect("/commTrack/") else: # Show an error page return
HttpResponseRedirect("/commTrack/commtrack/invalid/")

and here is my model.py

class CustomUserModelBackend(ModelBackend):
    def authenticate(self, username=None, password=None):
        try:
            user = self.user_class.objects.get(username=username)
            if user.check_password(password):
                return user
        except self.user_class.DoesNotExist:
            return None

    def get_user(self, user_id):
        try:
            return self.user_class.objects.get(pk=user_id)
        except self.user_class.DoesNotExist:
            return None

    @property
    def user_class(self):
        if not hasattr(self, '_user_class'):
            self._user_class =
get_model(*settings.CUSTOM_USER_MODEL.split('.', 2))
            if not self._user_class:
                raise ImproperlyConfigured('Could not get custom user
model')
        return self._user_class

class CustomUser(User): """User with app settings.""" title =
models.ForeignKey(Title) timezone = models.CharField(max_length=50,
default='Africa/Dar es Salaam') # Use UserManager to get the create_user
method, etc. objects = UserManager()




Any idea plz.
thanks in advance.
Denis.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.


Reply via email to