Incorrect {{root_path}} in classes derived from AdminSite

25 views
Skip to first unread message

Vlastimil Zima

unread,
Sep 9, 2009, 3:33:33 AM9/9/09
to Django users
Hello,
I found out, that if I made derived class of
django.contrib.admin.sites.AdminSite admin generated by this AdminSite
in unable to to create correct links e.g. for Logout (http://
127.0.0.1:8000/admin/Nonelogout/), Change Password (http://
127.0.0.1:8000/admin/Nonepassword_change/), etc. (examples are from
index page). I am not sure whether it is mistake at my site or
somewhere else.

Everything I changed since createproject and syncdb:

- add 'django.contrib.admin' to INSTALLED_APPS
- create sites.py :

from django.contrib.admin.sites import AdminSite

class TestAdminSite(AdminSite):
def get_urls(self):
"""
So far call super.get_urls, prepared for extensions
"""
urlpatterns = []
urlpatterns.extend( super(TestAdminSite, self).get_urls() )
return urlpatterns
def urls(self):
return self.get_urls()
urls = property(urls)

admin_site = TestAdminSite()

- generate admin in urls.py :

from django.conf.urls.defaults import *
from sites import admin_site
urlpatterns = patterns('',
(r'^admin/', include(admin_site.urls)),
)

Although there are no registered models, it can be observed that links
are not correct.

Any idea how to solve this problem or confirm that it is a bug will be
helpful.

Ramiro Morales

unread,
Sep 9, 2009, 6:40:08 AM9/9/09
to django...@googlegroups.com
On Wed, Sep 9, 2009 at 4:33 AM, Vlastimil Zima <vlastim...@gmail.com> wrote:
>
> Hello,
> I found out, that if I made derived class of
> django.contrib.admin.sites.AdminSite admin generated by this AdminSite
> in unable to to create correct links e.g. for Logout (http://
> 127.0.0.1:8000/admin/Nonelogout/), Change Password (http://
> 127.0.0.1:8000/admin/Nonepassword_change/), etc. (examples are from
> index page). I am not sure whether it is mistake at my site or
> somewhere else.

We'll need to know what released version or SN revision of Django you are using
to be able to help you.

--
Ramiro Morales
http://rmorales.net

Vlastimil Zima

unread,
Sep 9, 2009, 8:08:37 AM9/9/09
to Django users
Django1.1

On Sep 9, 12:40 pm, Ramiro Morales <cra...@gmail.com> wrote:

Ramiro Morales

unread,
Sep 9, 2009, 11:31:49 AM9/9/09
to django...@googlegroups.com
On Wed, Sep 9, 2009 at 4:33 AM, Vlastimil Zima <vlastim...@gmail.com> wrote:
>
> Hello,
> I found out, that if I made derived class of
> django.contrib.admin.sites.AdminSite admin generated by this AdminSite
> in unable to to create correct links e.g. for Logout (http://
> 127.0.0.1:8000/admin/Nonelogout/), Change Password (http://
> 127.0.0.1:8000/admin/Nonepassword_change/), etc. (examples are from
> index page). I am not sure whether it is mistake at my site or
> somewhere else.
>
> Everything I changed since createproject and syncdb:
>
> - add 'django.contrib.admin' to INSTALLED_APPS
> - create sites.py :
>
> from django.contrib.admin.sites import AdminSite
>
> class TestAdminSite(AdminSite):
>   def get_urls(self):
>       """
>       So far call super.get_urls, prepared for extensions
>       """
>       urlpatterns = []
>       urlpatterns.extend( super(TestAdminSite, self).get_urls() )
>       return urlpatterns
>     def urls(self):
>       return self.get_urls()
>   urls = property(urls)
>
> admin_site = TestAdminSite()

You need to provide a name parameter to the constructor of your AdminSite
sub-class as described in the relevant Django 1.1 admin app documentation:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#adminsite-objects
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#multiple-admin-sites-in-the-same-urlconf

>
> - generate admin in urls.py :
>
> from django.conf.urls.defaults import *
> from sites import admin_site
> urlpatterns = patterns('',
>   (r'^admin/', include(admin_site.urls)),
> )
>
> Although there are no registered models, it can be observed that links
> are not correct.
>
> Any idea how to solve this problem or confirm that it is a bug will be
> helpful.
>

--
Ramiro Morales
http://rmorales.net

Vlastimil Zima

unread,
Sep 9, 2009, 12:16:59 PM9/9/09
to Django users
Neither name nor app_label fixed situation.
AdminSite instance django.contrib.admin.site is constructed without
any names and it works.
In documentation is written: "If no instance name is provided, a
default instance name of admin will be used."

On Sep 9, 5:31 pm, Ramiro Morales <cra...@gmail.com> wrote:
> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#adminsite-obj...http://docs.djangoproject.com/en/dev/ref/contrib/admin/#multiple-admi...

Ramiro Morales

unread,
Sep 9, 2009, 7:14:22 PM9/9/09
to django...@googlegroups.com
On Wed, Sep 9, 2009 at 1:16 PM, Vlastimil Zima <vlastim...@gmail.com> wrote:
>
> Neither name nor app_label fixed situation.
> AdminSite instance django.contrib.admin.site is constructed without
> any names and it works.
> In documentation is written: "If no instance name is provided, a
> default instance name of admin will be used."

Ah, then you either need to either override only the get_urls() method
and leave the urls() method/url property one to be handled Django or to
write your urls() method so it returns the three tuple the rest of the
admin code is expecting (you are retuning a a single value).

This new capability was added in Django 1.1 core as part of
the URL namespacing changes and and is described both here:

http://docs.djangoproject.com/en/dev/topics/http/urls/#defining-url-namespaces

and in the Django 1.1 release notes.

HTH,

Vlastimil Zima

unread,
Sep 10, 2009, 3:53:16 AM9/10/09
to Django users
That was the problem, thanks a lot.

On Sep 10, 1:14 am, Ramiro Morales <cra...@gmail.com> wrote:
> On Wed, Sep 9, 2009 at 1:16 PM, Vlastimil Zima <vlastimil.z...@gmail.com> wrote:
>
> > Neither name nor app_label fixed situation.
> > AdminSite instance django.contrib.admin.site is constructed without
> > any names and it works.
> > In documentation is written: "If no instance name is provided, a
> > default instance name of admin will be used."
>
> Ah, then you either need to either override only the get_urls() method
> and leave the urls() method/url property one to be handled Django or to
> write your urls() method so it returns the three tuple the rest of the
> admin code is expecting (you are retuning a a single value).
>
> This new capability was added in Django 1.1 core as part of
> the URL namespacing changes and and is described both here:
>
> http://docs.djangoproject.com/en/dev/topics/http/urls/#defining-url-n...
Reply all
Reply to author
Forward
0 new messages