未定义名称请求

时间:2014-05-07 17:45:52

标签: python bottle

我试图访问我的html中的请求对象但是无法访问它..如何将请求对象传递给我的HTML

<html>
<head>
</head>
<body>
<form action="/start" method="post">
   <span>Username:</span>
   <input type="text" name="username">
   <span>Password:</span>
   {{ request.url }}
   <input type="password" name="password">
   <input type="submit" value="Sign in">
</form>
</body>
</html>

test.py

from bottle import route, run, template, redirect

@route('/hello')
def hello():
    return template('login')
run(host='localhost', port=8082, debug=True)

1 个答案:

答案 0 :(得分:2)

您应该能够将request传递到模板中,如下所示:

from bottle import route, run, template, redirect
import bottle

@route('/hello')
def hello():
    return template('login', request=bottle.request)