Question

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?

Was it helpful?

Solution

Alternatively, you can use:

from __future__ import unicode_literals

>>> 'a'
'a'
>>> from __future__ import unicode_literals
>>> 'a'
u'a'

See __future__ — Future statement definitions.

OTHER TIPS

Setting the string in forms.py to unicode solved the problem:

link = forms.URLField(label=u"קישור")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top