On Tue, Oct 9, 2012 at 8:01 PM, shiva krishna <[email protected]> wrote:
> I am using python web.py framework to create a small web application which
> has just
>
> 1. Login screen (Authentication)
>
> 2. Screen with list of records(After succesfull login)
>
> Presently i am trying to create a login screen authentication
>
> I have created an `index.py` file with code as below
>
> **index.py**
>
>     import os
>     import sys
>     import web
>     from web import form
>     from web.contrib.auth import DBAuth
>
>     render = web.template.render('templates/')
>
>     urls = (
>       '/',   'Login',
>     )
>
>     app = web.application(urls, globals())
>     db = web.database(dbn='mysql', db='Python_Web', user='root',
> pw='redhat')
>
>     class Login:
>
>         login_form = form.Form(
>             form.Textbox('username', form.notnull),
>             form.Password('password', form.notnull),
>             form.Button('Login'),
>             )
>
>         def GET(self):
>             form = self.login_form()
>             return render.login(form)
>
>         def POST(self):
>     #        if not self.login_form.validates():
>     #            return render.login(self.login_form)
>             post = self.login_form()
>             username = post['username'].value
>             print username,">>>>>>>>>>>>>>>>>>>>>>username"
>             password = post['password'].value
>             ident = db.select('user', where='user_login=$username',
> vars=locals())
>
>     if __name__ == "__main__":
>         web.internalerror = web.debugerror
>         app.run()

You need to call form.validates() or form.fill() to fill the form with
values from input data.

Typical use is:

    form = self.login_form()
    # render the form again if there are errors
    if not form.validates():
        return form.render()
    # do something with the form here

Anand

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to