使用Python的Django框架做Web应用时的中文乱码问题

问题描述:
在两个地方使用了中文:一个是python源文件中,一个是html模板中。在用浏览器查看该页时出现乱码,形如:"????",但是将浏览器的编码改为gb2312或gbk是正常的(浏览器默认使用utf8编码)

python代码:
[code="python"]
#coding=utf-8

from django.shortcuts import render_to_response

address = [
{'name':'张三', 'address':'地址一'},
{'name':'李四', 'address':'地址二'}
]

def index(request):
return render_to_response('list.html', {'address':address})
[/code]

html代码:
[code="html"]

通讯录

{% for user in address %} {% endfor %}
姓名地址
{{ user.name }}{{ user.address }}

[/code]

html模板是用GBK编码写的

html文件编码与浏览器的html编码必须一致

可以用eclipse修改文件编码