我的Latin1编码标记在Python3.4中不起作用,但在Python2.7中可以正常工作

2024-09-27 22:26:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用瓶子.py、Mongodb和Python。在

我在python 2.7代码的顶部有一个标记:

# #-- coding: latin1 --

我使用编码来获取瓶子请求,例如:

^{pr2}$

我还在每个网页的顶部加了meta charset="•ISO-8859-1",一切都很好。然而,当我试图迁移到python3.4时,没有收到错误消息,但是我的代码似乎是UTF-8而不是拉丁语1(重音字符不会按应该的方式打印)。在

我希望你能帮助我。我缺少一些迁移工作的东西,也许他们更新了编码名称或其他东西,但我一直在阅读Python3.4编码,找不到我的错误。在

代码如下:

@bottle.post('/newpost')
def post_newpost():
    title = bottle.request.forms.get("subject")
    post = bottle.request.forms.get("body")
    beneficios = bottle.request.forms.get("beneficios")
    CheckboxTramite= bottle.request.forms.getlist("CheckboxTramite")
    cookie = bottle.request.get_cookie("session")
    username = sessions.get_username(cookie)
    dependencia = sessions.get_dependencia(cookie)

return bottle.template("newpost_template1", dict(subject="", body = "", errors="", tags="", username=username, dependencia=dependencia, beneficios="", CheckboxTramite=[],))

Tags: 代码瓶子bottle编码getcookierequest错误
1条回答
网友
1楼 · 发布于 2024-09-27 22:26:31

我不知道为什么瓶子输出的编码会改变,因为默认情况下它被记录为utf-8。但是the documentation声明您可以通过设置Response.charset属性来更改它。看看“更改默认编码”下面的示例。在

这与Python源文件的编码无关,因为问题的一些注释暗示了这一点。在

相关问题 更多 >

    热门问题