Didina Deen
Didina Deen

Reputation: 195

Show ASCII characters in django template (python 2)

I'm trying to show the word "Año" in a template but I get an emtpy string.

I do have

# -*- coding: utf-8 -*-

at the beginning of my views.py

I've tried in my view:

 unicode(myString)

 myString.encode(encoding='UTF-8')

I've tried in my template:

 {{n.name|safe}}

None of the methods are working for me.

In my mysql table the word is fine.

In my views I get the data like this:

cursorMYSQL.execute(query)
table_names = cursorMYSQL.fetchall()

In my template:

{%if table_names%}
    {% for n in table_names %}
        <option value="{{n.name}}" name="{{n.name}}">{{n.name}}</option>
    {% endfor %}
{%endif%}

Upvotes: 0

Views: 485

Answers (1)

Didina Deen
Didina Deen

Reputation: 195

Finally I solved it with

myString.decode('latin1')

I had to check my DB as Joel Goldstick said, as some tables were enconded in utf-8 and some in latin1, which I didn't know.

Changing my mysql table charset to CHARSET=utf8mb4 didn't work either.

Upvotes: 1

Related Questions