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

  • SEARCH
  • Home
  • 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 4260020
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:51:51+00:00 2026-05-21T05:51:51+00:00

I have a django application and I want to add my own auth validation

  • 0

I have a django application and I want to add my own auth validation and check if the user is expired (check the expiration date from some of my models). I want to raise a ValidationError in the login page with appropriate message if user is expired. What’s the best way to do that?

Thanks, Alex

  • 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-05-21T05:51:51+00:00Added an answer on May 21, 2026 at 5:51 am

    If you REALLY want to do your own custom authentication, you should read custom backends in the Django Documentation.

    You probably don’t want to do your own though. It sucks. Really. Unless there is a really really good reason, you should avoid your own authentication. The main reason being, that many django apps stop working if you don’t use the built in User model. If you need to authenticate against an existing source, that’s a valid reason for creating your own backend. But there are pitfalls, and you still probably want to use the built in User model for your custom backend.

    You should tell us why you want to do your own custom authentication, and perhaps we can help you achieve your requirement, without writing a custom backend.

    Edit

    Ok, I think I understand what you mean now. What (I think) you want, is a custom authentication form. We currently use custom form (though we have a different unavoidable backend), so you should be able to use the following quite easily.

    from django.contrib.auth.forms import AuthenticationForm
    from django import forms
    from myproject.myapp.models import MyClass
    
    class CustomAuthForm(AuthenticationForm):
    
        def clean(self):
            cleaned_data = super(CustomAuthForm, self).clean()
            user = self.user_cache # set by super class
            if user.my_class.expired:
                raise forms.ValidationError('This User has Expired!')
            return cleaned_data
    

    Then, to use this custom authentication form, you need a URL in your urls.py:

    from myproject.myapp.forms import CustomAuthForm
    
    url(r'^login/$', 'django.contrib.auth.views.login', name='login', 
        kwargs={'template_name':'youproject/login.html', 'authentication_form':CustomAuthForm}),
    

    I see now that your question originally stated you wanted custom validation, not authentication. My apology for not reading your question correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Django application which takes the lat/lon from a user's coordinates via
HI I have a django application running on app engine and I want to
I have a Django 1.3 application. I have several management commands. I want each
I have an application that uses Django 1.3 installed in python's site-packages. I want
I have some unit tests I've written to test my Django application. One test
I have a many-to-many relationship in my django application where I use the add
Is it possible to customize a django application to have accept localized date format
I have a Django application which sometimes needs to send some data through TCP
I want to have RSS feeds in my Django application, which should be viewable
In a django application I have the following model: class Appointment(models.Model): #some other fields

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.