python - 配置 django 设置以使用 1.4.1。加载模板错误

标签 python django django-templates osqa

这是我得到的错误:

ImproperlyConfigured: Error importing template source loader django.template.loaders.filesystem.load_template_source: "'module' object has no attribute 'load_template_source'"

这是我的加载器模板代码:

if DEBUG:
    TEMPLATE_LOADERS = [
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',      
    ]
else:
    TEMPLATE_LOADERS = [
        ('django.template.loaders.cached.Loader',(
            'django.template.loaders.filesystem.load_template_source',
            'django.template.loaders.app_directories.load_template_source',
            'forum.modules.template_loader.module_templates_loader',
            'forum.skins.load_template_source',
            )),
    ]

当我从 Internet 下载该项目时,所有这些代码都在那里。我正在尝试设置 OSQA使用 these instructions .我正在运行 MS SQL Server 并安装了 Python 2.6。关于如何修复此错误的任何帮助 (当我尝试运行 manage.py runserver 并点击设置我的东西的 http 链接时发现。错误在命令行中弹出)。我是 DjangoPython 的新手,所以我真的不知道如何诊断正在发生的事情。

最佳答案

如果您查看 template loader types 上的文档(向下滚动到缓存模板加载器部分),看起来当你配置缓存加载器时你仍然需要传递它 Loader 类 - 所以你想改变你的配置看起来像这样:

if DEBUG:
    TEMPLATE_LOADERS = [
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',      
    ]
else:
    TEMPLATE_LOADERS = [
        ('django.template.loaders.cached.Loader',(
            'django.template.loaders.filesystem.Loader',
            'django.template.loaders.app_directories.Loader',
            'forum.modules.template_loader.module_templates_loader',
            'forum.skins.load_template_source',
            )),
    ]

我不确定 forum 应用程序的加载程序是什么,但您可能还需要 Loader 类(您需要阅读文档在那个应用程序上弄清楚 - 并非所有第三方模板加载器都与缓存加载器一起工作)。

关于python - 配置 django 设置以使用 1.4.1。加载模板错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11904609/

相关文章:

javascript - Django-Jquery 循环遍历所有选项

python - 点到线段的投影 Python Shapely

python - 使用 Pandas Dataframe 仅选择一个日期小于另一个日期的行

python - Django 使用 Mysql 返回无日期时间字段

python - DRF始终返回 "Authentication credentials were not provided"

django - 将额外数据附加到 Django 中的 request.POST

python - Python IOError : [Errno 2] No such file or directory: 'data.csv' 错误

python - Django KeyError {% if in %}

python - 在 django 中 prepopulated_fields = {"slug": ("title", )} 不显示所有单词

python - NoReverseMatch at/polls/〉为什么第0行会出错?