Label for input field isn't rendered when ends with non ASCII character
<p>I encountered a strange behavior while using Django forms. In my <code>forms.py</code> I have a user register form, and for each field I have set a label. Then in view I am passing the form into the context. In html file I'm using the form as follows:</p>

<pre><code>{% for field in UserForm %}
&lt;div class="form-group"&gt;
    {{field.label_tag}}
    {{field}}
&lt;/div&gt;
{% endfor %}
</code></pre>

<p>my form looks like this:</p>

<pre><code>class UserForm(UserCreationForm):

    first_name = forms.CharField(
        label = 'ImiÄ',
        max_length=255,
        widget=forms.TextInput(
            attrs={
                'class': 'form-control',
                'name': 'Name',
                'placeholder': 'ImiÄ',
                'required' : '',

            }
        )
    )

    last_name = forms.CharField(
        label = 'Nazwisko',
        max_length=255,
        widget=forms.TextInput(
            attrs={
                'class': 'form-control',
                'name': 'Surname',
                'placeholder': 'Nazwisko',
                'required' : '',

            }
        )
    )
</code></pre>

<p>The problem is that for one field a label is not shown,
the <code>&lt;label&gt;</code> tag is not even generated in output html file.</p>

<p>The problematic label is: <code>label = 'ImiÄ',</code>. I noticed that when a label ends with non ASCII character, the label is not generated. I tested that for other field labels.</p>

<p>I have included <code># -*- coding: utf-8 -*-</code> at the beginning of the <code>forms.py</code> (otherwise python throws an error about non ASCII characters in file), so that's not the source of this problem. Also I checked in Notepad++ that this file really uses UTF-8 encoding.</p>

<p>I'm using Django 1.9 and python version is 2.7.6.</p>

<p>Any help is appreciated.</p>

<p>Python 2.7 have 2 types of string, normal and unicode. Normal string (used by default) can't store any unicode characters. In your form you are using normal strings for label. That is causing issues.</p>

<p>You can either use unicode in that string:</p>

<pre><code>    first_name = forms.CharField(
        label = u'ImiÄ',
        max_length=255,
        widget=forms.TextInput(
            attrs={
                'class': 'form-control',
                'name': 'Name',
                'placeholder': u'ImiÄ',
                'required' : '',

            }
        )
    )
</code></pre>

<p>Or set all strings in this file to be treated as unicode by default, by adding:</p>

<pre><code>from __future__ import unicode_literals
</code></pre>

<p>At the very top of the file (right after setting encoding for file).</p>

<p>In python 3 that was changed, so by default all strings are treated as unicode.</p>

python html django