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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:59:42+00:00 2026-05-20T09:59:42+00:00

I am presently using the login view and the AuthenticationForm from django.contrib.auth.views to login

  • 0

I am presently using the login view and the AuthenticationForm from django.contrib.auth.views to login users.

Now, I would like to extend this solution to prepopulate the username field from the request object (I can infer the username if visitors are authenticated elsewhere). Because I am lazy and would like to keep dry, I wonder if this is possible without replicating the entire login view code.

I am aware of dynamic initial values in Django, but I cannot see how these might be passed into the login view (which does not accept form instances as parameter).
On the IRC channel, it was suggested that I extend the AuthenticationForm to process the request, however (as far as I understand), the request is not always passed on to the form (rather only when the form is submitted, which would be too late).

The only alternative I can think of is writing a custom login view to add initial values, which would basically replicate the code from the contrib.auth package (plus passing initial values to the form).

My question, then, is this: Is there a simpler alternative, one that would get by without copying code? Any hints would be much appreciated. 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-05-20T09:59:43+00:00Added an answer on May 20, 2026 at 9:59 am

    The request is passed into the form on GET – see line 54 of django.contrib.auth.views. So yes, extending the form to take the username seems like the best way to go. Something like (untested):

    class ExtendedAuthForm(AuthenticationForm):
        def __init__(self, request=None, *args, **kwargs):
            if request is not None:
                username = request.get_username_however()
                initial = kwargs.get('initial', {})
                initial_default = {'username': username}
                initial_default.update(initial)
                kwargs['initial'] = initial_default
            super(ExtendedAuthForm, self).__init__(request, *args, **kwargs)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to return a collection plus a single value. Presently I am using
I am presently developing a web service using Ruby on Rails. I wish to
I am invoking a camera using an intent and clicking a picture. Presently I
I am reading data from multiple serial ports. At present I am using a
I am using such code to present a new view, I don't it's good
I am using Devexpress's SpinEdit control on a view. There is an event on
I have recently designed a web application that I would like to write in
Does anybody know if in Jmeter, using a View Results Tree node, you should
I have an application, built using MVC, that produces a view which delivers summary
I'm using storyboard for the UI and I have the following: A login window

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.