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 8258557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:34:50+00:00 2026-06-08T02:34:50+00:00

I have an application where we have sub-classed the Django ‘User’ object into, say,

  • 0

I have an application where we have sub-classed the Django ‘User’ object into, say, ‘AppAccount’ object which has additional attributes. Now I have a view where I do the following:

appAccountObject.backend = 'django.contrib.auth.backends.ModelBackend'
login(request, appAccountObject) 
redirect(someOtherView) 

Now according to pdb, request.user is an instance of AppAccount right after the login() call, but request.user is a Django User instance in the first line of someOtherView.

Why is the redirect call changing the User object back to the normal Django User? How can I avoid this?

Also, is the above code correct? Should adding the backend attribute be okay to bypass a call to authenticate? If not, what should the correct way of doing this be: I want to login a user automatically, without their credentials and then redirect to another view which is wrapped by a @login_required decorator.

Thanks.

  • 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-08T02:34:53+00:00Added an answer on June 8, 2026 at 2:34 am

    A redirect causes a whole new request from the user’s browser, hence the user object has to be fetched from the database again based on the session cookie and assigned to request.user. This happens in the authentication middleware. Unless you’ve written your own version of this, it’s always going to use the default user class.

    This is just one of the reasons why it’s a bad idea to subclass User. Instead, extend it with a UserProfile class with a OneToOne relation to User.

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

Sidebar

Related Questions

Brief: I have a sub classed AuthorizeAttribute in my framework in which I am
In many application I often have algorithms which make use of dedicated sub-algorithms (or
I am using the standard User model (django.contrib.auth) which comes with Django. I have
I have an application that contains a main Activity, which has a very simple
I have a document-based application and I have sub-classed NSDocument and provided the required
We have subclassed the Silverlight Application class to add some additional functionality and then
I have an application in vb.net that starts with a sub function do some
I have a main application, and a bunch of sub-applications (they are separate apps,
i have a problem to distributing application with 2 project (one project with sub-project
I have several tabs in my application, and each tab loads a different sub-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.