0

我使用 Bottle 框架制作了一个简单的程序。我收到此错误:

'TypeError: login_submit() 只需要 1 个参数(给定 0)'

代码是:

# -*- coding: cp1252 -*-
import codecs
from bottle import route, run, template


@route('/login')
def login_form():
    return '''<form method="POST" action="/login">
            <input name="name" type="text" />
            <input name="password" type="password" />
            <input type="submit" />
          </form>'''

@route('/login', method='POST')
def login_submit(request):
  name = request.forms.get('name')
  password = request.forms.get('password')
  if check_login(name, password):
    return "<p>Your login was correct</p>"
  else:
    return "<p>Login failed</p>"

run(host='localhost', port=8080)
4

1 回答 1

1

从 docs导入请求,而不是将其作为参数:

from bottle import post, request

...

@route('/login', method='POST') # or @post('/login')
def login_submit():
  name = request.forms.get('name')
  password = request.forms.get('password')
  if check_login(name, password):
    return "<p>Your login was correct</p>"
  else:
    return "<p>Login failed</p>"
于 2013-07-20T03:52:28.963 回答