I'm trying to run a quick Django application that pulls data from Google AdWords and exposes the names of accounts that are managed by an agency. When doing so, I get the following error:
UnicodeEncodeError at /account-hierarchy/
'ascii' codec can't encode character u'\xe9' in position 5: ordinal not in range(128)
Here's the snippet:
<table class="pretty-table">
<thead>
<tr>
<td>Customer ID</td>
<td>Client Name</td>
<td>Can Manage Clients</td>
<td>Account Currency</td>
</tr>
</thead>
{% for account in managed_accounts %}
<tr>
{% for field in account %}
<td>{{ field }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
where the call to {{ field }}
is the problematic line.
I have already added
<meta http-equiv="content-type" content="text/html; charset=utf-8">
to the template I am rendering, but it still fails, so I believe the problem is not on the HTML template, but rather on the Python/Django engine.
Any ideas how I can fix it?
Here's the View code that renders the template:
def account_hierarchy(request):
manager_ids = settings.MANAGER_IDS
managed_accounts = []
for manager_id in manager_ids:
managed_accounts.extend(adwords_utils.getManagedAccounts(manager_id))
return render_to_response('simple-table.html', {"managed_accounts": managed_accounts})
UPDATED Question
- Python Version: 2.7.6
- Models.py is currently empty
What's also curious is that if I remove this:
{% for field in account %}
<td>{{ field }}</td>
{% endfor %}
and I just print out the main array:
{{ managed_accounts }}
it works just fine. Not sure what's going on.
Curious fact #2: As I managed to output the full array, I checked for character 'é' and I didn't find it on the final output. Not sure where it was coming from.