Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8711383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:51:49+00:00 2026-06-13T04:51:49+00:00

I am using web.py framework for designing a small web application, presently i have

  • 0

I am using web.py framework for designing a small web application, presently i have created a login page and code is below

index.py

import web
from web import form
from web.contrib.auth import DBAuth
import MySQLdb as mdb

render = web.template.render('templates/')


urls = (
  '/',   'Login',
  '/projects',  'Projects',
  '/logout',   'Logout',
)

app = web.application(urls, globals()) # Creating an instance(object) app which is the mediator between our classes and the web.It will handle browser requests and serve your pages

web.config.debug = False
db = web.database(dbn='mysql', db='Python_Web', user='root', pw='redhat')
settings = {}

if web.config.get('_session') is None:
    session = web.session.Session(app,web.session.DiskStore('sessions'),initializer={'user':'anonymous','loggedin':False})
    web.config._session = session
else:
    session = web.config._session

auth = DBAuth(app, db, session,**settings)


def logged():
    if session['loggedin'] == 1:
        return True
    else:
        return False
class Login:

    # field validators
    username_required = form.Validator("Username not provided", bool)
    password_required = form.Validator("Password not provided", bool)

    # form validators
    login_details_required = form.Validator("Please Enter Login Details", lambda f: f["username"] or f["password"])

    login_form = form.Form( 
        form.Textbox('username', username_required),
        form.Password('password',password_required,description="Password"),
        form.Button('Login'),
        )

    def GET(self):
        if logged():
            raise web.seeother('/projects')
        else:
            form = self.login_form()
            return render.login(form)

    def POST(self):

        if not my_form.validates(dict(username="", password="small")):
            return render.login(form)

        i = web.input()
        username = i.username.strip()
        password = i.password.strip()
        user = auth.authenticate(username, password)
        if not user:
            session.loggedin = False
            return render.login_error(form) 
        else:
            auth.login(user)
            session.loggedin = True
            session.user = i.username.strip()
            raise web.seeother('/projects')

if __name__ == "__main__":
    web.internalerror = web.debugerror
    app.run()  

Here in the above code my intention is

1.If username not provided it should display "Username not provided" when clicked on Login

2.If password not provided it should display "password not provided" when clicked on Login

3.If password provided but length is less than 7 characters it should display "Password length should be minimum 7 characters" when clicked on Login(Of course this validation concept suits when creating a user by selecting password )

4.If Both not provided it should display "Please Enter Login Details" when clicked on Login

5.If Login details not matched it should display "Invalid Username or Password" when clicked on Login and if login Details matched should redirect to next page

In the above code when login details matched its redirecting to next page successfully and if not displaying Invalid username or password through return render.login_error(form) (I copied same html code from login(form) page to login_error(form) and added "Invalid Username or Password" line extra in that)

Also i created a regex expression for password validation and hope thats working(I dint checked exactly) because if password length is less than 7 characters it is not redirecting to next page instead redirecting to same login page, but at the same time i want to display on the browser like the message "Password length should be minimum 7 characters" which i am unable to do(dont know how to do)

Also i had given username as form.notnull() validation in Form creation as above, when i tried to click login it is checking whether the form validates or not and if not redirecting to the same login page, but i want to display the message "Please enter the username" and also for password if not provided

  1. Whether the above regex will work correctly (i dint worked on regex until now)

  2. How to display the above validation messages on browser if username,password, not provided on the browser, because i had created another html page just for the Invalid username or password message to appear on the browser when details are incorrect

Whether we can do all this validations in single html file(like login.html) itself ? ,
i have tried a lot but i am unable catch the process going on here, if so we can save of creating more than one html for individual messages

can anyone let me know on how to solve the above common problems ?
Don’t mind for my queries as this is my first step in web applications and i dint worked on web applications before

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:51:51+00:00Added an answer on June 13, 2026 at 4:51 am

    You can add many validators to the same input field and there are also form level validations.

    from web import form
    
    
    # field validators
    username_required = form.Validator("Username not provided", bool)
    password_required = form.Validator("Password not provided", bool)
    password_length = form.Validator("Password length should be minimum 7 characters", lambda p: p is None or len(p) >= 7)
    
    # form validators
    login_details_required = form.Validator("Please Enter Login Details", lambda f: f["username"] or f["password"])
    
    def check_login(f):
        # check for login here
        return False
    valid_credentials = form.Validator("Invalid username or password", check_login)
    
    login_form = form.Form(
        form.Textbox('username', username_required),
        form.Password('password', password_required, password_length, description="Password"),
        form.Button('Login'),
        validators=[login_details_required, valid_credentials],
    )
    
    
    my_form = login_form()
    if not my_form.validates(dict(username="", password="small")):
        print my_form.render_css()
    
    if not my_form.validates(dict(username="notnull", password="just-enough")):
        print my_form.render_css()
    

    Note that login_details_required won’t be triggered, because form-level validation is only triggered when all fields validators have passed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this web application using Spring Web Flow framework. In my main page
I am designing a web application using the ASP.net MVC framework. I would like
We have been using a web application framework to build apps that need to
I am designing a plugin system for our web based application using Spring framework.
Okay, so I'm designing a stand-alone web service (using RestLET as my framework). My
This is using the web app framework, not Django. The following template code is
I'm writing a web application using the Catalyst framework . I'm also using a
We are developing a web application using Spring framework and Hibernate ORM. As far
Using Nitrogen, the Erlang web framework , I have the following method that receives
For past 7 months I have been designing web applications using open source technologies

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.