【问题标题】:django 1.11 Cannot extend templates recursively when using non-recursive template loadersdjango 1.11 使用非递归模板加载器时无法递归扩展模板
【发布时间】:2018-07-30 21:09:11
【问题描述】:

我有 django 1.11.2 并安装了 django-mobile=0.7.0。

当我想进入管理面板时,我收到一个错误:

ExtendsError at /admin/
Cannot extend templates recursively when using non-recursive template loaders
Request Method: GET
Request URL:    http://127.0.0.1:8000/admin/
Django Version: 1.11.2
Exception Type: ExtendsError
Exception Value:    
Cannot extend templates recursively when using non-recursive template loaders

我在第一行收到错误{% extends "admin/base.html" %}

{% extends "admin/base.html" %}
{% load admin_static %}{% load suit_tags %}

{% block branding %} {% endblock branding %}

我的模板设置:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR, 'templates'),
        ],
        'APP_DIRS': False,
        'OPTIONS': {
            'context_processors': [
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.debug',
                'django.template.context_processors.i18n',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'django.template.context_processors.tz',
                'django.template.context_processors.csrf',
                'django.template.context_processors.request',
                'django.contrib.messages.context_processors.messages',
                'django_mobile.context_processors.flavour',
            ],
            'loaders': (
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
                'django.template.loaders.eggs.Loader',
                'django_mobile.loader.Loader',
            ),
            'debug': DEBUG,
        },
    },
]
TEMPLATE_LOADERS = TEMPLATES[0]['OPTIONS']['loaders']

中间件类:

MIDDLEWARE_CLASSES = [
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django_mobile.middleware.MobileDetectionMiddleware',
    'django_mobile.middleware.SetFlavourMiddleware',
]

【问题讨论】:

  • django-mobile 0.7 于近两年前发布。我不认为你可以期望它与一年后发布的 Django 1.11 一起使用。

标签: python django templates loader django-middleware


【解决方案1】:

自述文件中的installation instructionsdjango_mobile.loader.Loader 应该是loaders 中的第一个 项,例如:

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

目前,你已经在最后了,所以 Django 会先尝试使用其他加载器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-27
    • 2013-02-23
    • 1970-01-01
    • 2015-05-20
    相关资源
    最近更新 更多