所以我在python manage.py shell
中测试我的代码,但是我得到了以下错误:AttributeError: 'NoneType' object has no attribute 'find'
。在
以下是我在应用程序的models.py
中所做的:
from djmoney.models.fields import MoneyField
from django.template.loader import render_to_string
from django.db import models
from datetime import date
import mandrill
<;…>
^{pr2}$回溯似乎表明问题出在render_to_string()
,但我看不出我在实现上做了什么错误:我测试了shell中是否存在该模板(它是一个电子邮件模板)。事实上,没有上下文的render_to_string('email/invoice.html')
可以很好地工作。问题在于上下文。在
我试着在shell中使用一个简单的dict,比如context = {'hst': 123}
,这也很管用。因为某些原因,它不喜欢我上面的格言,并抱怨一个不典型的人。我单独检查了shell并确保它在每个字段中都存在一个值。在
你知道这个怪物是从哪里来的吗?在
编辑:这是完整的回溯
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/cyehia/Documents/Apps/gcap/rental/models.py", line 41, in email_invoice
msg_html = render_to_string('email/invoice.html', context)
File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/django/template/loader.py", line 99, in render_to_string
return template.render(context, request)
File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/django/template/backends/django.py", line 74, in render
return self.template.render(context)
File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/django/template/base.py", line 209, in render
return self._render(context)
File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/django/template/base.py", line 201, in _render
return self.nodelist.render(context)
File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/django/template/base.py", line 903, in render
bit = self.render_node(node, context)
File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/django/template/debug.py", line 79, in render_node
return node.render(context)
File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/django/template/debug.py", line 92, in render
output = force_text(output)
File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/django/utils/encoding.py", line 90, in force_text
s = six.text_type(s)
File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/djmoney/models/fields.py", line 133, in __str__
locale = self.__get_current_locale()
File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/djmoney/models/fields.py", line 103, in __get_current_locale
locale = translation.to_locale(translation.get_language())
File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 185, in to_locale
return _trans.to_locale(language)
File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 75, in to_locale
p = language.find('-')
AttributeError: 'NoneType' object has no attribute 'find'
问题似乎与incompatibly between Django 1.8 and django-money有关。我会尝试手动激活一种语言:
相关问题 更多 >
编程相关推荐