开发者

Web.py Form not posting?

I wrote the following based on a few different web.py examples I found, but im unable to get the login page to post, Any ideas why my code is sooo foobar?

p.s also why does it seem that I have to have web.config.debug set to false if I want to use sessions?

import web 
import db 
from web import form


login = form.Form(
    form.Textbox('username'),
    form.Password('password'),
    form.Button('Login'), )

urls = (
    '/', 'Index',
    '/login', 'Login',
    '/home', 'Home', )

web.config.debug = False 
app = web.application(urls, globals())
session = web.session.Session(app, web.session.DiskStore('sessions'))


class Login:
    def GET(self):
        f = login()
        return render.register(f)

    def POST(self):
        f = web.input()
        check = db.db_query('select * from users where username=? and password=?', (i.username, i.password))
        if check:
            session.loggedin = True
            session.username = i.username
            raise web.seeother('/home')
        else: return render.base("Those login details开发者_Python百科 don't work.")


class Index:
    def GET(self):
        return 'index'

class Home:
    def GET(self):
        return 'home'


if __name__ == '__main__':
    app.run()


Please check the example presented here ( http://webpy.org/cookbook/forms ), to me it seems that just doing form.Form(...) doesn't actually create the tag, so please check your output HTML.
Basically it's missing <form name="main" method="post"> ... </form> encompassing your elements (textinput, button)


You're using 'i' variable which was not defined...try using the 'f' the one you defined for web.input()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜