Code

Opened 3 years ago

Closed 22 months ago

Last modified 14 months 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

Description

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 3 years ago.

Download all attachments as: .zip

Change History (16)

comment:1 Changed 3 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 http://groups.google.com/group/django-developers/browse_frm/thread/fa3661888716f940/8b4d0cf8f34e5493

Also refs #8906.

comment:2 Changed 3 years ago by lukeplant

  • Type set to New feature

comment:3 Changed 3 years ago by lukeplant

  • Severity set to Normal

Changed 3 years ago by UloPe

comment:4 Changed 3 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 3 years ago by UloPe

  • Keywords dceu2011 added

comment:6 Changed 3 years ago by russellm

  • Triage Stage changed from Accepted to Ready for checkin

comment:7 Changed 3 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 3 years ago by jezdez

  • Triage Stage changed from Ready for checkin to Accepted

comment:9 Changed 3 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 3 years ago by jezdez

Yeah, that's fine.

comment:11 Changed 22 months 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 https://github.com/django/django/pull/343

comment:12 Changed 22 months 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
review.

comment:13 Changed 22 months ago by Tim Graham <timograham@…>

comment:14 Changed 14 months 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 14 months ago by dbrgn

  • Cc gezuru@… added

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.