Opened 5 years ago

Closed 3 years ago

Last modified 3 years ago

#15552 closed New feature (fixed)

LOGIN_URL should allow named urls

Reported by: WoLpH Owned by: nobody
Component: contrib.auth Version: 1.2
Severity: Normal Keywords: login_url logout_url login_redirect_url named_url url_tag dceu2011
Cc: gezuru@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


To adhere to the DRY principle it seems quite silly that one has to hardcode the LOGIN_URL, LOGOUT_URL and LOGIN_REDIRECT_URL.

It would be logical to simply use a named url so it always redirects to the login view you specified, regardless of the SCRIPT_NAME and your url configs.

Attachments (1)

t15552.patch (11.7 KB) - added by UloPe 4 years ago.

Download all attachments as: .zip

Change History (16)

comment:1 Changed 5 years ago by carljm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

I think this is a valid point, and the proposed solution is the right one. See also discussion at

Also refs #8906.

comment:2 Changed 5 years ago by lukeplant

  • Type set to New feature

comment:3 Changed 5 years ago by lukeplant

  • Severity set to Normal

Changed 4 years ago by UloPe

comment:4 Changed 4 years ago by UloPe

  • Easy pickings unset
  • Has patch set
  • UI/UX unset

I've added a patch that implements Alex Gaynor's suggestion from the thread mentioned above and basically applies the logic from redirect() to LOGIN_URL and LOGIN_REDIRECT_URL

comment:5 Changed 4 years ago by UloPe

  • Keywords dceu2011 added

comment:6 Changed 4 years ago by russellm

  • Triage Stage changed from Accepted to Ready for checkin

comment:7 Changed 4 years ago by jezdez

  • Patch needs improvement set

The resolve_url function fits better in the django.shortcuts module instead of a new django.utils.urls module.

comment:8 Changed 4 years ago by jezdez

  • Triage Stage changed from Ready for checkin to Accepted

comment:9 Changed 4 years ago by UloPe

I placed it in utils because I wasn't sure you'd want resolve_url as part of the "public" shortcuts module.
But if that is ok I'll update the patch.

comment:10 Changed 4 years ago by jezdez

Yeah, that's fine.

comment:11 Changed 3 years ago by floguy

  • Patch needs improvement unset

I've updated this patch for 1.5 trunk as of today and have submitted a pull request on GitHub

comment:12 Changed 3 years ago by Carl Meyer <carl@…>

  • Resolution set to fixed
  • Status changed from new to closed

In [a78dd109e6c81c49e90e36e9b793bad67c46c23c]:

Fixed #15552 -- LOGIN_URL and LOGIN_REDIRECT_URL can take URLpattern names.

Thanks UloPe and Eric Florenzano for the patch, and Malcolm Tredinnick for

comment:13 Changed 3 years ago by Tim Graham <timograham@…>

comment:14 Changed 3 years ago by dbrgn

The current implementation does not allow named url arguments, right?

I'm using django-social-auth and would like to point LOGIN_URL to resolve('socialauth_begin', args=('google-oauth2',)).

comment:15 Changed 3 years ago by dbrgn

  • Cc gezuru@… added
Note: See TracTickets for help on using tickets.
Back to Top