Configurable get_absolute_url for User model.

115 views
Skip to first unread message

wnielson

unread,
Oct 19, 2007, 4:52:57 PM10/19/07
to Django developers
I needed the ability to set a custom url for the User model, so I
modified the User model's `get_absolute_url` to allow endusers to
define an attribute, `AUTH_USER_URL`, in their settings file. `/users/
<username>/` is still the default, but can simply be overwritten.

I filed a ticked [1] and added a patch. The solution I came up with
allows `AUTH_USER_URL` to be fairly flexible, here are some examples:

AUTH_USER_URL = '/accounts/%(username)s/'
AUTH_USER_URL = '/users/%(last_name)s_%(first_name)s/'
AUTH_USER_URL = '/users/%(id)s/'

Any ``User`` object attribute can be defined.

[1] http://code.djangoproject.com/attachment/ticket/5783

James Bennett

unread,
Oct 19, 2007, 5:12:38 PM10/19/07
to django-d...@googlegroups.com
On 10/19/07, wnielson <wnie...@gmail.com> wrote:
> I needed the ability to set a custom url for the User model, so I
> modified the User model's `get_absolute_url` to allow endusers to
> define an attribute, `AUTH_USER_URL`, in their settings file. `/users/
> <username>/` is still the default, but can simply be overwritten.

http://www.djangoproject.com/documentation/settings/#absolute-url-overrides

--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

wnielson

unread,
Oct 19, 2007, 6:39:05 PM10/19/07
to Django developers
*sigh*

I must have passed over that one a hundred times without seeing it
once...

On Oct 19, 2:12 pm, "James Bennett" <ubernost...@gmail.com> wrote:


> On 10/19/07, wnielson <wniel...@gmail.com> wrote:
>
> > I needed the ability to set a custom url for the User model, so I
> > modified the User model's `get_absolute_url` to allow endusers to
> > define an attribute, `AUTH_USER_URL`, in their settings file. `/users/
> > <username>/` is still the default, but can simply be overwritten.
>

> http://www.djangoproject.com/documentation/settings/#absolute-url-ove...

James Bennett

unread,
Oct 19, 2007, 7:03:29 PM10/19/07
to django-d...@googlegroups.com
On 10/19/07, wnielson <wnie...@gmail.com> wrote:
> I must have passed over that one a hundred times without seeing it
> once...

At some point I'd like to see the get_absolute_url() method on the
User model rewritten to use the permalink() decorator, which would do
away with the need to override on a per-install basis. I'm not sure
exactly how that'd work, though, since we'd have to decide on a naming
scheme for the auth URLs.

Jeremy Dunck

unread,
Oct 19, 2007, 7:56:44 PM10/19/07
to django-d...@googlegroups.com
On 10/19/07, James Bennett <ubern...@gmail.com> wrote:
> At some point I'd like to see the get_absolute_url() method on the
> User model rewritten to use the permalink() decorator, which would do
> away with the need to override on a per-install basis. I'm not sure
> exactly how that'd work, though, since we'd have to decide on a naming
> scheme for the auth URLs.

I've thought for a while that it might be useful to be able to imply a
name URL pattern based on the view itself. True, generic views and
similar need disambiguation-- but it seems to me that it should be at
least optional to have the URL mapping to auth.login magically named
auth-login, etc.

Reply all
Reply to author
Forward
0 new messages