Django admin popup links are broken

2019-08-13 19:01发布

问题:

I'm having a problem with the django admin popups: on creating a new object related to the one I'm currently working on (e.g., the User model and the Groups he belongs to), by clicking on the plus sign near the form field I expect the browser to open a popup served by the add view of the related model but instead what I experience is the serving of the add view inside the page itself. Practically speaking, the popup is not working as it should be.

The link on the plus sign (from the standard User model admin page, Group field) is the following: /admin/auth/group/add/?_to_field=id&_popup=1

The same behaviour is happening on other models, and this suggest me that something is wrong with the settings file (maybe what is missing is a javascript handler...)

Do you have any idea of what can be wrong ? I'm using django 1.8 with the django grappelli interface.

Here is my setting file (the core part):

import os

PROJECT_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))

MEDIA_ROOT = '/webapps/example/media/'
MEDIA_URL = '/media/'

STATIC_ROOT = '/webapps/example/static/'
STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(PROJECT_ROOT, 'static'),
)

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'django.contrib.staticfiles.finders.FileSystemFinder',
)

TEMPLATES = [{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'APP_DIRS': False,
    'DIRS': [os.path.join(PROJECT_ROOT, 'templates')],
    'OPTIONS': {

        'context_processors': (
            'django.contrib.auth.context_processors.auth',
            'django.core.context_processors.debug',
            'django.core.context_processors.i18n',
            'django.core.context_processors.media',
            'django.core.context_processors.static',
            'django.core.context_processors.tz',
            'django.contrib.messages.context_processors.messages',

            "django.core.context_processors.request",
        ),

        'loaders': (
            'django.template.loaders.filesystem.Loader',
            'django.template.loaders.app_directories.Loader',
        ),

        'debug': False
    }
}]

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

TEST_RUNNER = 'django.test.runner.DiscoverRunner'

ROOT_URLCONF = 'example.urls'

WSGI_APPLICATION = 'example.wsgi.application'

INSTALLED_APPS = (
    # Grappelli custom admin, needs to be defined before the admin app.
    'grappelli',

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # 'django.contrib.sites',

    # 'django.contrib.humanize',
    # 'django.contrib.sitemaps',

    # 3rd-party app
    'gunicorn',
    'django_extensions',

    # Local apps
    ...
)

SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'

# Grappelli settings.
GRAPPELLI_ADMIN_TITLE = SITE_NAME

回答1:

Django introduced changes to the Javascript that creates the admin popups. Grappelli isn't currently fully compatible with Django 1.8.

This issue is already reported on Github. For more information you can follow the ticket: https://github.com/sehmaschine/django-grappelli/issues/600