Reputation: 409
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>"
Upvotes: 1
Views: 2628
Reputation: 781
Nice tutorial to get started with http://www.giantflyingsaucer.com/blog/?p=3598
OR if you are looking for some class based views try https://github.com/techchunks/bottleCBV
Upvotes: 0
Reputation:
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.
Upvotes: 0
Reputation: 432
Use the kwarg* method='POST' within your @route decorator instead of @get or @post.
Like this:
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>"
Good luck.
Upvotes: 1
Reputation: 798606
You've goofed up and called something else "bottle.py".
Upvotes: 5