python - Django 属性错误 : 'module' object has no attribute 'is_usable'

标签 python django

在 Django 中调用 url 时出现以下错误。 它以前是有效的,我猜这与我所做的一些意外更改有关,但我不知道它们是什么。

感谢之前的帮助, 罗伯特

Environment:

Request Method: GET Request URL: http://localhost:8000/time/ Django Version: 1.2 Python Version: 2.6.1 Installed Applications: ['django.contrib.auth',  'django.contrib.contenttypes',  'django.contrib.sessions',  'django.contrib.sites',  'django.contrib.messages',  'django.contrib.admin',  'djlearn.books'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware')


Traceback: File "/Library/Python/2.6/site-packages/django/core/handlers/base.py" in get_response
  100.                     response = callback(request, *callback_args,
**callback_kwargs) File "/Users/rhenru/Workspace/django/djlearn/src/djlearn/../djlearn/views.py" in current_datetime
  16.     return render_to_response('current_datetime.html',{'current_date':now,}) File "/Library/Python/2.6/site-packages/django/shortcuts/__init__.py" in render_to_response
  20.     return HttpResponse(loader.render_to_string(*args,
**kwargs), **httpresponse_kwargs) File "/Library/Python/2.6/site-packages/django/template/loader.py" in render_to_string
  181.         t = get_template(template_name) File "/Library/Python/2.6/site-packages/django/template/loader.py" in get_template
  157.     template, origin = find_template(template_name) File "/Library/Python/2.6/site-packages/django/template/loader.py" in find_template
  128.             loader = find_template_loader(loader_name) File "/Library/Python/2.6/site-packages/django/template/loader.py" in find_template_loader
  111.         if not func.is_usable:

Exception Type: AttributeError at /time/ Exception Value: 'module' object has no attribute 'is_usable'

最佳答案

看起来 Django 正在寻找一个可用的模板加载器,但在 settings.TEMPLATE_LOADERS 中发现了一些不符合模板加载器功能协议(protocol)的东西(简要描述 here。)

是否有可能您最近的更改之一是 settings.TEMPLATE_LOADERS 或自定义模板加载器?如果是后者,您的模板函数需要一个 is_usable 属性,大概设置为 True

关于python - Django 属性错误 : 'module' object has no attribute 'is_usable' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2941108/

相关文章:

python - 使用 setattr() 将字符串转换为变量

python - tastypie PUT 有效但 POST 无效

python - 将文件夹永久添加到 Python 的路径

python - 如何 "switch to one of the Agg backends"?

Django 连接无法与 Azure Active Directory 正常工作

django - 在 View 中返回 json 文件

python - 具有 Crispy-forms VariableDoesNotExist 的 Django

python - 更改 django-rest-auth 中的错误消息

python - 使用 setuptools 可执行访问 yaml 配置文件

Python 3 Bokeh Heatmap 矩形简单示例未在图中显示任何内容