Alternatively, you can use:
from __future__ import unicode_literals
>>> 'a'
'a'
>>> from __future__ import unicode_literals
>>> 'a'
u'a'
سؤال
Consider the following Django form:
# -*- coding: UTF-8 -*-
...
class VideoForm(forms.Form):
link = forms.URLField(label="LINK")
title = forms.CharField(max_length=50)
This works fine, giving a form with a field whose label is LINK
. However, when I change the link line to:
link = forms.URLField(label="קישור")
I get the following error:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa8 in position 0: ordinal not in range(128)
...
In template /Users/adamatan/Personal/hashmabir_design/flip_classroom_hackathon/web/flipped/core/templates/
...
core/add_video.html, error at line 23
...
{% trans field.label_tag %} {{ field }}
How do I encode the template in utf-8?
المحلول
Alternatively, you can use:
from __future__ import unicode_literals
>>> 'a'
'a'
>>> from __future__ import unicode_literals
>>> 'a'
u'a'
نصائح أخرى
Setting the string in forms.py
to unicode solved the problem:
link = forms.URLField(label=u"קישור")