joolie
joolie

Reputation: 409

I just want to know how bottle work.When I run the following code it ended in an import error:cannot import name get .pls help me

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

Answers (4)

Adeel
Adeel

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

user642922
user642922

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

Cameron Goodale
Cameron Goodale

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

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798606

You've goofed up and called something else "bottle.py".

Upvotes: 5

Related Questions