【问题标题】:Settings.py not working as expected DjangoSettings.py 没有按预期工作 Django
【发布时间】:2015-11-27 18:48:56
【问题描述】:

晚上好,我的 django 项目遇到了一个奇怪的问题。在我开始开发它的 Ubuntu 上,我没有发现任何问题,但是当我尝试在我的 OS X El Capitan 中移动它时,我要么收到以下错误之一:

1) 当APP_DIRS 设置为True 时:在定义加载程序时不得设置app_dirs

2) 当APP_DIRS 设置为False 或删除时:没有名为“admin_tools.template_loaders”的模块

在这个 settings.py 中我做错了什么吗?

这就是我的 settings.py 的样子:

SITE_ID = 1

DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'admin_tools',
    'admin_tools.theming',
    'admin_tools.menu',
    'admin_tools.dashboard',
    'tinymce',
    'crispy_forms',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.sites',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'management',
    'myApp',
    'easy_thumbnails',

)


TINYMCE_DEFAULT_CONFIG = {
    'plugins': "table,spellchecker,paste,searchreplace",
    'theme': "advanced",
    'cleanup_on_startup': True,
    'custom_undp_redo_levels': 10,
}

MIDDLEWARE_CLASSES = (

    'django.contrib.sessions.middleware.SessionMiddleware',
    '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',
)

ROOT_URLCONF = 'myproject.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'debug': DEBUG,
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'django.core.context_processors.request',
                'django.template.context_processors',

            ],
            'loaders': [
                ('django.template.loaders.cached.Loader', [
                    'django.template.loaders.filesystem.Loader',
                    'django.template.loaders.app_directories.Loader',
                ]),
                'admin_tools.template_loaders.Loader',
        ]
        },

    },
]

WSGI_APPLICATION = 'myproject.wsgi.application'


# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/


AUTH_USER_MODEL = 'management.IfasicUser'

AUTHENTICATION_BACKENDS = (

    'django.contrib.auth.backends.ModelBackend',
)

LOGIN_URL = 'django.contrib.auth.views.login'

LOGIN_REDIRECT_URL = 'home'

MEDIA_URL = '/media/'
STATIC_URL = '/static/'


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


CRISPY_TEMPLATE_PACK = 'bootstrap3'

任何帮助将不胜感激。

【问题讨论】:

    标签: python django django-settings


    【解决方案1】:

    App_DIRS 设置为True 时:在定义加载程序时不得设置app_dirs

    正如错误所说,您必须在定义 loaders 时删除 app_dirs 设置。

    APP_DIRS 设置为False 或删除时:没有名为“admin_tools.template_loaders”的模块

    尝试升级到今天发布的 0.7.1。查看the changelog,缓存的模板加载器似乎存在错误。

    【讨论】:

    • 我确实有这是我的 pip 冻结列表:Django==1.8.6 django-admin-tools==0.6.0 django-crispy-forms==1.5.2 django-debug-toolbar= =1.4 django-tinymce==2.0.6 easy-thumbnails==2.2.1 hgtools==6.3 Pillow==3.0.0 psycopg2==2.6.1 sqlparse==0.1.18 wheel==0.24.0
    • 尝试将 django-admin-tools 升级到 0.7.1。
    • 在这种情况下,我会尝试删除缓存的模板加载器并改用文件系统和应用程序目录加载器,看看 0.7.1 是否真的解决了这个问题。
    • 通过将('django.template.loaders.cached.Loader', [...]), 替换为'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', 来禁用缓存的模板加载器。如果这样可行,那么看起来 0.7.1 还没有修复缓存加载程序的错误。
    猜你喜欢
    • 2021-09-23
    • 2013-09-02
    • 1970-01-01
    • 1970-01-01
    • 2023-02-22
    • 2019-05-25
    • 2018-09-11
    • 2013-01-08
    • 1970-01-01
    相关资源
    最近更新 更多