404 error in admin interface with mod_python and >=django-1.1

已查看 133 次
跳至第一个未读帖子

Jan Meier

未读,
2010年6月11日 04:49:252010/6/11
收件人 Django users
Hi,

I am serving my django project with mod_python and ran into a problem
regarding the admin interface (django.contrib.admin). If DEBUG = False
is set in settings.py the admin interface generates 404 error messages
when clicking on any of my models, for example to add a new entry. The
django shipped models work without any problems. If I set DEBUG = True
everything works fine as expected. It is odd that the models show up
in the interface but clicking them generates 404 errors.
The problem occurs with django-1.1.2 and django-1.2.1, django-1.0.*
works fine.
I tested this on debian and ubuntu with different projects. To hunt
the problem down I tested with mod_wsgi, which has the same problem.

Here is my apache configuration with mod_python:

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/jan/tmp/my_project
Options Indexes FollowSymLinks

<Location />
SetHandler python-program
PythonHandler django.core.handlers.modpython
PythonPath "['/home/jan/tmp/my_project/', ] +
sys.path"
SetEnv DJANGO_SETTINGS_MODULE my_project.settings
PythonOption django.root /mynew
PythonDebug On
</Location>
<Location "/static/">
SetHandler None
</Location>
<Location "/media">
SetHandler None
</Location>
</VirtualHost>

Here is my settings.py configuration file:

DEBUG = False
TEMPLATE_DEBUG = DEBUG
[...]
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
)
ROOT_URLCONF = 'my_project.urls'
TEMPLATE_DIRS = (
'/home/jan/tmp/my_project/templates'
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'my_project.my_app',
)

My urls.py url configuration file looks like this:

from django.conf.urls.defaults import *

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^admin/', include(admin.site.urls)),
)

And my model my_app/models.py looks as follows:

from django.db import models
from django.contrib import admin

class Blubb(models.Model):
x = models.IntegerField()

admin.site.register(Blubb)

Any ideas what could be wrong?

Kind regards,

Jan

Karen Tracey

未读,
2010年6月11日 09:30:542010/6/11
收件人 django...@googlegroups.com
On Fri, Jun 11, 2010 at 4:49 AM, Jan Meier <j...@codejunky.org> wrote:
And my model my_app/models.py looks as follows:

from django.db import models
from django.contrib import admin

class Blubb(models.Model):
       x = models.IntegerField()

admin.site.register(Blubb)

Any ideas what could be wrong?


Yes, you've got your admin registrations in your models.py file. models.py won't necessarily be loaded early in a production environment with DEBUG=False, so these registration calls are not running before you start using admin. Move admin registrations to an admin.py file and call admin.autodiscover() in your urls.py file (see http://docs.djangoproject.com/en/dev/ref/contrib/admin/#hooking-adminsite-instances-into-your-urlconf) and the problem will go away.

Karen
--
http://tracey.org/kmt/

Jan Meier

未读,
2010年6月11日 10:28:202010/6/11
收件人 Django users

On 11 Jun., 15:30, Karen Tracey <kmtra...@gmail.com> wrote:
> Yes, you've got your admin registrations in your models.py file. models.py
> won't necessarily be loaded early in a production environment with
> DEBUG=False, so these registration calls are not running before you start
> using admin. Move admin registrations to an admin.py file and call
> admin.autodiscover() in your urls.py file (seehttp://docs.djangoproject.com/en/dev/ref/contrib/admin/#hooking-admin...)
> and the problem will go away.

Thank you very much, that solved my problem. :-)

Regards,
Jan
回复全部
回复作者
转发
0 个新帖子