web.py使用模板的时候如果有中文的话会乱码?要怎么办?比如下面测试两个字就会乱码,求大神帮忙。。。

py代码如下:

import web

render = web.template.render("templates")

urls = ( 
    '/(.*)', 'hello',)

app = web.application(urls, globals())

class hello:        
    def GET(self,name):
        return render.hello2(name)

if __name__ == "__main__":
    app.run()

html代码如下:

$def with(name)
<html>
<head>
	<meta http-equiv='content-type',content='text/html;charset=utf-8'>
	<title>hello</title>
</head>
<body>
	<h1>测试</h1>
	<form action="/blog/123" method="Post">
		<input type="text" name="username" value="$name">
		<input type="password" name="password" value="">
		<input type="submit" value="submit">
	</form>
</body>
</html>


慕粉0128549381
浏览 3088回答 2
2回答

慕函数9285021

python 脚本开头,一般约定加一个脚本编码的定义如果默认的情况下,python对中文的编码方式是gbk编码,在脚本处理你的模板之后,就编程gbk的编码了,你在浏览器中使用utf-8 就会出现乱码#! usr/env/bin python# -*-encoding:utf-8-*-
打开App,查看更多内容
随时随地看视频慕课网APP