Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8773033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:11:26+00:00 2026-06-13T18:11:26+00:00

I am trying to use the django inbuilt AuthenticationForm to allow users to login

  • 0

I am trying to use the django inbuilt AuthenticationForm to allow users to login using their email address and password. I have changed the authenticate function to accept both username and email to authenticate users.

This is my code so far:

     def loginuser(request):
          if request.POST:
            """trying to use AuthenticationForm to login and add validations"""
            form = AuthenticationForm(request.POST.get('email'),request.POST.get('password'))
            user = form.get_user()
            if user.is_active:
                login(request,user)
                render_to_response('main.html',{'user':user})
            else:
                HttpResponse('user not active') 
          render_to_response('login.html')   

But this is not how the authentication form is used, at least not the correct way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:11:27+00:00Added an answer on June 13, 2026 at 6:11 pm

    An example. You can see django.contrib.auth.forms for derails (search AuthenticationForm in the file forms.py).

    f = AuthenticationForm( { 'username': request.POST.get( 'email' ), 'password': request.POST.get( 'password' ) } )
    try:
        if f.is_valid():
            login( f.get_user() )
        else:
            # authentication failed
    except ValidationError:
        # authentication failed - wrong password/login or user is not active or can't set cookies.
    

    So, modify your code to:

     def loginuser(request):
          if request.POST:
            """trying to use AuthenticationForm to login and add validations"""
            form = AuthenticationForm(request.POST.get('email'),request.POST.get('password'))
            try:
                if form.is_valid():
                    # authentication passed successfully, so, we could login a user
                    login(request,form.get_user())
                    render_to_response('main.html',{'user':user})
                else:
                    HttpResponse('authentication failed') 
            except ValidationError:
                 HttpResponse('Authentication failed - wrong password/login or user is not active or can't set cookies')
    
          render_to_response('login.html')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use django-social-auth to allow my users to log into the
Hello I'm a newbie trying to use django to register some users, I have
I am trying to use django-socialauth ( http://github.com/uswaretech/Django-Socialauth ) for authenticating users for my
I am trying to use django-social-auth to implement google openid login into my app,
I have a small app I'm working on where I'm trying to use Django's
I am using webapp2, ndb model. I was trying to use django model forms
I'm trying to use iexact in my Django app. I have items in my
I am using Django 1.3 and trying to use .exists() on a model entry
Let's say trying to use django.views.generic.create_update.create_object to allow the user to a blog entry
I am trying to use the Django admin to allow rudimentary management of page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.