Proposal: Allow LOGIN_URL to be a callable

3 views
Skip to first unread message

Ulrich Petri

unread,
Oct 14, 2009, 6:35:01 PM10/14/09
to Django developers
Hi,

in some projects I've had to interface with external authentication
sources that did expect the return-to URL in other formats than "%
(LOGIN_URL)s?%(redirect_field_name)s=%(url)s" (In one specific case it
was, e.g. required that the return URL had to be base64 encoded).

AFAIK there are currently two ways to accomplish that:

a) Set LOGIN_URL to a view that reformats the return URL and redirects
again (thereby having two redirects in a row)
b) Monkey patch user_passes_test (formerly _CheckLogin)

Neither of which I think are very good options.

So I would like to propose another option:
Allowing LOGIN_URL to be a callable which, in case of
user_passes_test, gets passed the redirect_field_name and return path
and returns the complete target URL.
Deciding whether the given string is a callable or an URL should be
simple; If the string contains at least one '/' it's an URL otherwise
it's a callable.

If it is felt this would be worthwhile to have in django (or if it is
even a good idea) I would be happy to provide a patch.

Thanks,
Ulrich

Jonathan Lukens

unread,
Oct 15, 2009, 6:04:18 AM10/15/09
to Django developers
+1

This would also be a help in cases where you have different sets of
users and have to use a) to redirect them to the view appropriate to
their account type.
Reply all
Reply to author
Forward
0 new messages