![](/img/trans.png)
[英]Python: ValueError: unsupported format character ''' (0x27) at index 1
[英]Python, Django: ValueError: unsupported format character '(' (0x28) at index 3
有人可以向我解释为什么这会引发ValueError吗? (使用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}
这是错误(通过芹菜错误电子邮件发送):
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
检查您的消息目录条目。
_(...)
调用将消息目录中的unicode值替换为一个(如果有),并且该消息引发此异常。 交换%
和前面的空格可以做到这一点,例如:
>>> '►% (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.