Code

Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#11563 closed (invalid)

Models are not registered at the moment when AdminSite.get_urls() runs, only at mod_wsgi environment

Reported by: daybreaker Owned by: nobody
Component: Contrib apps Version: master
Severity: Keywords: admin urls wsgi
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I'm using Django 1.1rc1 on Python 2.5.2 + mod_wsgi 1.3.1 + Apache 2.2.8 on a Ubuntu machine. I have never installed python-django package on this machine--this is a clean custom install.

Everything works fine when I run my project via the test server.

But after attaching it to Apache/mod_wsgi, all /admin/appname/modelname/ urls stopped to work. I've inspected the source code of Django, and used logging module around the AdminSite class, and finally found that this problem only occurs when I use mod_wsgi.

All model class registration should be done BEFORE get_urls() method runs, and this is correct with the internal test server, but not with mod_wsgi.

I don't have any idea why this happens, but if this is a bug of Django, it seems very critical. (I hope not...)

Attachments (0)

Change History (5)

comment:1 Changed 5 years ago by daybreaker

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

For more information, I add some bits of my codes:

# in admin.py
from django.contrib import admin
from myproject.myapp.models import MyModel # imported for custom admin-actions

class MyModelAdmin(admin.ModelAdmin):
...


# in models.py
from django.contrib import admin

class MyModel(models.Model):
...

from myproject.myapp.admin import *
admin.site.register(MyModel, MyModelAdmin)

comment:2 Changed 5 years ago by daybreaker

I think urls.py is also important:

from django.conf.urls.defaults import *
from django.contrib import admin

urlpatterns = patterns('',
    # my custom urls...

    # Uncomment the next line to enable the admin:
    (ur'^admin/', include(admin.site.urls)),
)

comment:3 Changed 5 years ago by Alex

  • Resolution set to invalid
  • Status changed from new to closed

Your problem is that you should be registering with the admin in your admin.py file and then using admin.autodiscover() at the top of your urls.py. In the future please ask user questions on either the django-users mailing list or the #django IRC channel on freenode.

comment:4 Changed 5 years ago by anonymous

Thanks, but I've already questioned on the IRC and nobody responded, and stackoverflow also didn't help me. :)

However, I have still another question (well, should it go to "user"-things?) -- autodiscover() is the only way that is recommended as the official option? And is this a strange behaviour or not?

comment:5 Changed 3 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.