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

时间:2012-08-10 15:17:07

标签: 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',
            )),
    ]

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

2 个答案:

答案 0 :(得分:26)

如果你查看template loader types上的文档(向下滚动到缓存的模板加载器部分),看起来当你配置缓存的加载器时,你仍然需要传递它Loader类 - 所以你和#39; d想要将配置更改为:

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个类(您需要阅读有关该文档的文档)应用程序来解决这个问题 - 并非所有第三方模板加载器都使用缓存的加载程序。)

答案 1 :(得分:4)

  1. 打开包含Twissandra项目提取内容的文件夹中的'settings.py'文件。
  2. 搜索,'TEMPLATE_LOADERS =('并在其中,搜索,'django.template.loaders.filesystem.load_template_source'。注释此行并添加'django.template.loaders.filesystem.Loader'。
  3. 同样,在'TEMPLATE_LOADERS =(',search,'django.template.loaders.app_directories.load_template_source'中,并将其替换为'django.template.loaders.app_directories.Loader'。
  4.   

    P.S。我解决了我的问题并感谢How to fix the Django error displayed when loading Twissandra for the first time?