37,719
社区成员
发帖
与我相关
我的任务
分享
# -*- coding: utf-8 -*-
#中文测试一下
import bottle
#import peewee
from bottle import route, run, get, post, request
@route('/')
def hello():
return "Hello World! 你好世界"
@get('/login')
def login_form():
return """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
</head>
<body>
<form method="POST" action="/login">
<input name="name" type="text" />
<input name="password" type="password" />
<input type="submit" />
</form>
</body>
</html>"""
@post('/login')
def login_submit():
name = request.forms.get('name')
password = request.forms.get('password')
#print(name,type(name),"张三")
return """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
</head>
<body>
name: %s , password: %s, 其它:%s
</body>
</html>""" %(name,password,"张三")
run(host='localhost', port=8080, debug=True)
name = request.forms.name
详细解释见http://bottlepy.org/docs/dev/tutorial.html,关于"WTForms support"的部分。name = request.forms.get('name')
name得到的是str,而不是unicode str。改成:
name = request.forms.getunicode('name')