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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:03:56+00:00 2026-05-16T09:03:56+00:00

I’m relatively new to django.. In the app that I’m building, there are multiple

  • 0

I’m relatively new to django..

In the app that I’m building, there are multiple types of users (ie User1, User2, User3) that are all inheriting from django.contrib.auth.models.User and upon login, each user should be redirected to a success page depending on what type of user they are.

In views.py:

def login_attempt(request):

user = request.user
data = {}


username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:    
    if user.is_active:
        login(request, user)

        try: 
            User1.objects.get(username = user.username)
            type = "undergrad"
        except ObjectDoesNotExist:
            pass

        try:
            User2.objects.get(username = user.username)
            type = "grad"
        except ObjectDoesNotExist:
            pass

        try:
            User3.objects.get(username = user.username)
            type = "sponsor"
        except ObjectDoesNotExist:
            pass

        return render_to_response (
                "templates/success_"+type+".html",
                data,
                context_instance=RequestContext(request)
        )

    else:
        return render_to_response (
                "templates/fail1.html",
                data,
                context_instance=RequestContext(request)
        )
else:
    return render_to_response (
            "templates/fail2.html",
            data,
            context_instance=RequestContext(request))

and type(user) is <class 'django.contrib.auth.models.User'>

I’m currently running tests via “manage.py test” — authentication and redirects are working for User1 and User2 successfully, however it doesn’t authenticate for User3 and returns the “fail2.html” template. All other tests with User3 have returned valid results.

Any suggestions? This is my first question post, so feel free to ask questions if I’ve left relevant information out!

Thanks in advance.

  • 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-16T09:03:57+00:00Added an answer on May 16, 2026 at 9:03 am

    Not really an answer for your question, but why not use a user profile to determine your type and other data specific to the UserX classes? They are easy to set up, allow you to store additional User information, and allows you to continue using the built in User objects.

    The profile classes are pretty easy (I lifted this from The Django Book, Chapter 12):

    class MySiteProfile(models.Model):
        # This is the only required field
        user = models.ForeignKey(User, unique=True)
    
        # The rest is completely up to you...
        type = models.CharField(maxlength=100, blank=True)
    

    Beyond that, you change on item in settings.py, and set up a trigger to automagically create the profile on User creation, and you’re good to go.

    Your resulting view code would be drastically simplified, too:

    def login_attempt(request):
        user = request.user
        data = {}
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        if user is not None:    
            if user.is_active:
                login(request, user)
                type = user.get_profile().type
    
                return render_to_response (
                    "templates/success_"+type+".html",
                    data,
                    context_instance=RequestContext(request)
                )
    
            else:
                return render_to_response (
                        "templates/fail1.html",
                        data,
                        context_instance=RequestContext(request)
                    )
        else:
            return render_to_response (
                    "templates/fail2.html",
                    data,
                    context_instance=RequestContext(request)
                )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I have a text area in my form which accepts all possible characters from

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.