[英]Python, Django: ValueError: unsupported format character '(' (0x28) at index 3
Can somebody explain to me why this raises a ValueError? 有人可以向我解释为什么这会引发ValueError吗? (using Python 2.7)
(使用Python 2.7)
from django.utils.translation import ugettext as _
...
template = _('► %(user)s, random text here @[%(friend_id)s] more random text ◄◄◄'.decode('utf-8')) % {'user': friend_profile.user.first_name, 'friend_id': user.id}
This is the error (sent by celery error email): 这是错误(通过芹菜错误电子邮件发送):
File "/var/www/myapp/apps/app/tasks.py", line 54, in notify_friends_new_invite
template=_('��� %(user)s, random text here @[%(friend_id)s] more random text ���������'.decode('utf-8')) % {'user': friend_profile.user.first_name, 'friend_id': user.id},
ValueError: unsupported format character '(' (0x28) at index 3
Check your message catalog entry. 检查您的消息目录条目。
The _(...)
call replaces your unicode value with one from the message catalog (if available), and it is that message that throws this exception. _(...)
调用将消息目录中的unicode值替换为一个(如果有),并且该消息引发此异常。 Swapping the %
and the preceding space would do this, for example: 交换
%
和前面的空格可以做到这一点,例如:
>>> '►% (user)s, random text here @[%(friend_id)s] more random text ◄◄◄'.decode('utf-8') % {'user':u'foo', 'friend_id': u'bar'}
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: unsupported format character '(' (0x28) at index 3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.