Shiva Krishna Bavandla
Shiva Krishna Bavandla

Reputation: 26648

Error in using python web.py framework

I am working on python, i want to develop some simple web application which consists of 3 pages(forms)

  1. login screen which should validate username and password and redirect to 2nd page

  2. If user present it redirects to this page which consists of a list of records and add button to add another record

  3. When clicked on add record in 2nd page that should redirect to this page which consists of a simple form fields which takes data and saving to 2nd page as a record in a list when clicked on submit button

I don't want to use high level frameworks like django for the above small requirement so decided to use one of the following frameworks after googgling a lot

Wheezy.web ( https://bitbucket.org/akorn/wheezy.web/downloads)

web.py ( http://webpy.org/)

bottle (http://bottlepy.org/docs/dev/)

Flask (http://flask.pocoo.org/)

I started to use web.py framework and created a code.py file as indicated in the tutorial as below

code.py

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

urls = ( '/', 'index' )

if __name__ == "__main__": 
    app = web.application(urls, globals())
    app.run()  

After running the above file with python code.py the result is

sh-4.2$ python code.py 
http://0.0.0.0:8080/

i have change the ip and port as below

python code.py 192.168.1.112:2030

and tried to access through a browser , then i recieved the following error

<type 'exceptions.KeyError'> at /
u'index'
Python  /usr/lib/python2.7/site-packages/web/application.py in _delegate, line 418
Web     GET http://0.0.0.0:8080/
Traceback (innermost first)

    /usr/lib/python2.7/site-packages/web/application.py in _delegate
        cls = fvars[f] ...
    ▶ Local vars
    /usr/lib/python2.7/site-packages/web/application.py in handle
        return self._delegate(fn, self.fvars, args) ...
    ▶ Local vars
    /usr/lib/python2.7/site-packages/web/application.py in process
        return self.handle() ...
    ▶ Local vars

Request information
INPUT No data.
COOKIES No data.
...............

Actually when i type the url in to address bar a hello world message should appear as indicated in tutorial, but instead i am getting the above error.

  1. Can anyone please suggest on how to achieve the above requirement for developing a login screen in python without using a django framework and cgi in python
  2. I am unable to find out how to use these frameworks to use to develop because for example Wheezy.web ( https://bitbucket.org/akorn/wheezy.web/downloads) framework provided there is no docuemntation showing on how to create a file and start developing

please help me on the above scenarios

Upvotes: 2

Views: 1694

Answers (1)

Rob Wouters
Rob Wouters

Reputation: 16327

The line:

urls = ( '/', 'index' )

tells web.py the url / should be handled by a class index. You have not created such class and therefore you get the error. Fix it like so:

import web

urls = (
    '/', 'index'
)

class index:
    def GET(self):
        return "Hello, world!"

if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()

Upvotes: 3

Related Questions