On Sun, Sep 27, 2009 at 4:41 PM, Michael Williamson <
mikerwilliam...@yahoo.co.uk> wrote:

>
> Admin URLs do not seem to behaving themselves for me. My urls.py looks
> like this:
>
>    from django.conf.urls.defaults import *
>
>    from django.contrib import admin
>    admin.autodiscover()
>
>    urlpatterns = patterns('',
>        (r'^$', 'django.views.generic.simple.redirect_to', {'url': '/
> blog/'}),
>        (r'^blog/', include('mikesite.blog.urls')),
>        (r'^admin/', include(admin.site.urls)),
>    )
>
> When DEBUG=True, the admin interface works fine. When DEBUG=False, I
> get 404 errors when I attempt to access some URLs, such as /admin/blog/
> comment/add/, yet others, such as /admin/blog/ or /admin/auth/user/
> add/ work just fine.
>

You've listed one that doesn't work -- /admin/blog/comment/add.  Is comment
listed as a model at all under /admin/blog when things break?  Does
/admin/blog/comment/ work to show a change list of comment models?  Can you
bring up a detail page on an existing one?  Successfully change it?  I'm
trying to figure out if something has happened to cause the comment model to
disappear entirely from admin or if it's still partly there but broken.  If
only partially broken, what parts, exactly, are broken?


>
> After some digging around, I found that setting DEBUG=True fixes the
> problem since this enables validation in django.contrib.admin.sites
> (lines 69 to 72). When DEBUG is True,
> django.contrib.admin.validation.validate is called, which in turn
> calls django.db.models.get_apps().
>
> Putting django.db.models.get_apps() at the top of urls.py fixes the
> problem e.g.
>
>    from django.conf.urls.defaults import *
>
>    from django.contrib import admin
>    admin.autodiscover()
>
>    from django.db import models
>    models.get_apps()
>
>
It surprises me that putting something after the call to autodiscover()
could fix the problem.  It sounds like the call to autodiscover() is running
into trouble and not ending up registering all your models (causing 404
errors on some attempts to access them).  I don't see how putting something
after the call to autodiscover() would fix that.

This type of workaround sounds vaguely like some posted for this ticket:
http://code.djangoproject.com/ticket/10405.  You might read through that and
see if your models share characteristics with those in use by people who
have posted there.  If so, the root problem may be similar.



>    urlpatterns = patterns('',
>        (r'^$', 'django.views.generic.simple.redirect_to', {'url': '/
> blog/'}),
>        (r'^blog/', include('mikesite.blog.urls')),
>        (r'^admin/', include(admin.site.urls)),
>    )
>
> I can also fix the problem by slightly changing the admin regex like
> so:
>
>    from django.conf.urls.defaults import *
>
>    from django.contrib import admin
>    admin.autodiscover()
>
>    urlpatterns = patterns('',
>        (r'^$', 'django.views.generic.simple.redirect_to', {'url': '/
> blog/'}),
>        (r'^blog/', include('mikesite.blog.urls')),
>        (r'^admin/.*', include(admin.site.urls)),
>    )
>
>
Again, I don't understand how that would help.  Someone did recently open a
ticket (http://code.djangoproject.com/ticket/11918) saying that switching to
the older url pattern for admin worked with DEBUG=False where the current
one did not, but you haven't actually switched all the way back to the old
pattern here.  Plenty of people are using the 1.1 pattern without trouble,
so there's something in the configs where problems arise that is different.
We've not gotten enough specifics on the failing configs for me to have any
idea what it might be.  A small, recreatable example would help.

Karen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to