2

I'm using Django 1.1 rc1 and Apache 2.2.8 on Ubuntu with mod_wsgi 1.3.1 + Python 2.5.2.

Everything worked fine with Django's internal testing web server, but after migrating to Apache mod_wsgi, all urls like /admin/appname/modelname/ began not to work. They shows 404 not found errors with the following log:

...
^admin/ ^$
^admin/ ^logout/$
^admin/ ^password_change/$
^admin/ ^password_change/done/$
^admin/ ^jsi18n/$
^admin/ ^r/(?P<content_type_id>\d+)/(?P<object_id>.+)/$
^admin/ ^(?P<app_label>\w+)/$
The current URL, admin/account/userprofile/, didn't match any of these.

Strangely, /admin/appname/ and all other parts including my custom urls just work fine.

Is it a bug of Django or configuration issue? And how to solve it?

Achimnol
  • 1,551
  • 3
  • 19
  • 31

1 Answers1

1

I know that 1.1RC1 made some changes to the admin URL resolver to use namespaces: this might be your problem.

see here: http://docs.djangoproject.com/en/dev/releases/1.1-rc-1/

Other than that it looks like the URLs are not correct as the last line of the urls in the debug trace would only match /admin/app/ rather than /admin/app/xxxx. The information here might help.

for some reason this ^admin/ ^r/(?P\d+)/(?P.+)/$ doesn't look right wouldn't that give /admin//xxx/yyy/ ?

Edit: no it gives /admin/r/xxx/yyy/

I can't test this right now as I only have 1.0.2 available on this computer (and no mod_wsgi) - I will test on 1.1 when I get home tonight.

Edit: Looks like this

for model, model_admin in self._registry.iteritems():
    urlpatterns += patterns('',
       url(r'^%s/%s/' % (model._meta.app_label, model._meta.module_name),
            include(model_admin.urls))
    )
return urlpatterns

is not working for some reason, as the URLs are not included in the search path in the debug trace. Are the admin.py files correct?

Frozenskys
  • 4,290
  • 4
  • 28
  • 28
  • I also know those changes. (I was tracking the 'incorrect logout link in admin' ticket.) But if that's the reason, Django internal web server should not work properly also, but it was very fine. – Achimnol Jul 27 '09 at 12:59
  • For some reason the internal server seems more forgiving of this kind of problem. Are you sure that the settings.py and urls.py are the same in both locations? – Frozenskys Jul 27 '09 at 13:38
  • I've tried to run the test server directly on the project instance which are run via mod_wsgi, but I've faced this problem: http://stackoverflow.com/questions/1188205/how-to-specify-which-eth-interface-django-test-server-should-listen-on T_T – Achimnol Jul 27 '09 at 13:44
  • Also, that seems quite right. See the Django admin's source code here: http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/sites.py#L191 – Achimnol Jul 27 '09 at 13:48
  • It seems you are right there is a comment about urls starting with r being for 'view for web'? Are your permissions set correctly on the mod_wsgi server? and are your admin.py files correct? – Frozenskys Jul 27 '09 at 14:16
  • Well, I found the reason. Putting admin.autodiscover() at urls.py and admin.site.register() **at admin.py** works. I should have followed the documentation as it is, but unfortunately, my convention from Django 0.96-1.0.2 interrupted that. – Achimnol Jul 28 '09 at 00:25
  • And thanks for your attention and effort to find the solution. :) – Achimnol Jul 28 '09 at 00:27
  • Glad you got it sorted! I'm just happy to try and help a fellow Django User :) – Frozenskys Jul 28 '09 at 08:37