Can somebody explain to me why this raises a ValueError? (using 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. 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.