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 8655591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:04:11+00:00 2026-06-12T15:04:11+00:00

I am very new to web development, i am working on web.py framework to

  • 0

I am very new to web development, i am working on web.py framework to develop a small web application. suppose the login screen is localhost:9090/login, after the succesfull login it is redirecting to next page localhost:9090/details and after clicking another button add its again redirecting to localhost:9090/details/details_entry.

But when i tried directly localhost:9090/detailson browser its working and able to see the page without even logged in . So after googling a lot came to know that i need to use session concept , but i am tired as of now for busy schedule on searching about web concepts in google.
Can anyone let me know the concept of

  1. session (Actually why it is created and how to use it after login through page in python)

  2. Actually whats the complete concept of user authentication ,
    What are the steps to follow to create a user login page
    And steps to follow after user logged in with details
    what happens when user logouts and how to session code in python

I expect what ever the language it is but the concept of developing login screen and redirecting to next url by creating some sessions ids is same, so the user authentication concept is very important and may be this question is useful to others.

Edited Code

————–

Login.py

import os
import sys
import web
from web import form



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


urls = (
  '/',   'Login',
  '/projects',  'Projects',
  '/project_details',  'Project_Details',  
)

app = web.application(urls, globals())


web.config.debug = False
db = web.database(dbn='mysql', db='Python_Web', user='root', pw='redhat')
settings = {}
store = web.session.DBStore(db, 'sessions')
session = web.session.Session(app, store, initializer={'user': None})

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)
    i = web.input()
    username = i.username
    password = i.password
    user = db.select('user',
        where = 'user_login = $username', 
        vars = {'username': username}
    if username == user['username'] and password == user['password']:
        session.user = username
        raise web.seeother('/projects')

    else:
        return render.login_error(form)    

def auth_required(func):
    def proxyfunc(self, *args, **kw):
        print session.user,"=======> Session stored"
        try:
            if session.user:
              return func(self, *args, **kw)
        except:
            pass
        raise web.seeother("/")
    return proxyfunc

class Projects:

    project_list = form.Form( 
        form.Button('Add Project'),
        )

    @auth_required
    def GET(self):
        project_form = self.project_list()
        return render.projects(project_form)  

   def POST(self):
        raise web.seeother('/project_details')

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

In the above code after successfull login the page is redirecting to next page. Here i need to implement session concept, but i was stuck on where to implement session code in the above code. Can anyone please point me to a right way on where to write session code in the above py code for login page. After this worked need to implement logout functionality in the same py file

Edited code after implementing auth_required function and got the below error

Result:

Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/web/application.py", line 239, in process
    return self.handle()
  File "/usr/lib/python2.7/site-packages/web/application.py", line 230, in handle
    return self._delegate(fn, self.fvars, args)
  File "/usr/lib/python2.7/site-packages/web/application.py", line 420, in _delegate
    return handle_class(cls)
  File "/usr/lib/python2.7/site-packages/web/application.py", line 396, in handle_class
    return tocall(*args)
  File "/home/local/user/python_webcode/index.py", line 102, in proxyfunc
    print session.user,"=======> Session Stored"
  File "/usr/lib/python2.7/site-packages/web/session.py", line 71, in __getattr__
    return getattr(self._data, name)
AttributeError: 'ThreadedDict' object has no attribute 'user'
  • 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-12T15:04:12+00:00Added an answer on June 12, 2026 at 3:04 pm

    web.py provides session abstraction and several session stores. What you have to do, is to write login controller, display the form on GET, and find user and perform password check on POST, then store the user in session and kill the session on logout. After it you may write decorator that checks if user exists in session to use it over controller methods. Anyway, user authentication concept is mostly the same in all web apps.

    If you need already working solution for web.py then you may take a look at this module: http://jpscaletti.com/webpy_auth/

    If you decided to implement login youself, the simplest auth decorator will probably look like this:

    def auth_required(func):
        def proxyfunc(self, *args, **kw):
            try:
                if session.user:
                  # user is logged in
                  return func(self, *args, **kw)
            except:
                pass
            # user is not logged in
            raise web.seeother("/login")
        return proxyfunc
    

    Then you will be able to use @auth_required before your GET and POST methods in controllers like this:

    class Projects:
        @auth_required
        def GET(self):
            pass
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on my first asp.net/web development application. Obviously, I'm very new to asp.net
So I am very new to web development and working on a new project
I am very new to web development. I am currently using tablesorter jquery plugin
I'm very new to web app development and I thought I would start with
I'm very new to Rails and web development. I'm generating a bunch of objects
Hi I'm fairly new to web development and am stuck at the very first
I'm very new to web development, so bear with me =) Ok here is
I have just started working with a new company in a very small IT
I am very new to web development and the use of Open Source. I
Am very New to Web Page Development. In my website i have the help

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.