0
플라스크 학습을 시작했고 csv를 반복하여 멈 춥니 다.Python Flask - DictReader UnicodeDecode 문제로 고생했습니다.
행운 500 개를 나열하고 페이지에 인쇄하는 CSV를 실행하고 싶습니다. CSV에는 회사, 수익, 이익 및 순위 헤더가 있습니다.
내가 오류는 다음과 같습니다
다음File "/Project/FLASK/app/templates/companies.html", line 15, in block "content"
<td> {{ keys.Company }} </td>
UnicodeDecodeError: 'utf8' codec can't decode byte 0x8e in position 3: invalid start byte
이 companies.html입니다
{% extends "base.html" %}
{% block content %}
<table>
<tr>
<td> Company </td>
<td> Revenues </td>
<td> Profits </td>
<td> Rank </td>
</tr>
{% for keys in companies %}
<tr>
<td> {{ keys.Company }} </td>
<td> {{ keys.Revenues }} </td>
<td> {{ keys.Profits }} </td>
<td> {{ keys.Rank }} </td>
</tr>
{% endfor %}
</table>
{% endblock %}
마지막 내 views.py 파일입니다
@app.route('/companies')
def companies():
import csv
with open('companies.csv','rU') as f:
companies = csv.DictReader(f)
return render_template("companies.html",
title='Home',
companies=companies)
내가 {{키를 변경하는 경우 . 회사}} {{keys}} 사전이 표시되지만 keys.Company 또는 keys.Revenues로 변경하는 순간 같은 오류가 발생합니다
유니 코드로 읽지 않으면 어떻게 될까요? –