名称请求未定义

0 投票
1 回答
1009 浏览
提问于 2025-04-18 05:42

我想在我的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 个回答

2

你只需要像这样把 request 传递给模板就可以了:

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

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

撰写回答