1
from bottle import get, post, request

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

#@route('/login', method='POST')
@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>"
4

4 回答 4

5

你搞砸了,把别的东西叫做“bottle.py”。

于 2011-03-10T06:24:55.077 回答
1

在 @route 装饰器中使用 kwarg* method='POST' 而不是 @get 或 @post。

像这样:

from bottle import route, request

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

@route('/login', method='POST')
#@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>"

祝你好运。

于 2011-03-18T05:10:10.147 回答
0

You probably created a file named bottle.py within the same directory, try changing that to a new name like index.py or server.py then run the program again.

于 2013-08-13T12:53:59.557 回答
0

很好的教程,开始使用http://www.giantflyingsaucer.com/blog/?p=3598

或者,如果您正在寻找一些基于类的视图,请尝试https://github.com/techchunks/bottleCBV

于 2014-09-24T21:35:31.113 回答