Forums

Simple web.py not working

Not able to run web.py script from main page.

Directory structure as follows:

'/home/user/upperdirectory/lowerdirectory/projectname/'
                                                     /bin
                                                           app.py
                                                            __pycache__
                                                     /projectname

WSGI file as follows:

# +++++++++++ CUSTOM WSGI +++++++++++
# If you have a WSGI file that you want to serve using PythonAnywhere, perhaps
# in your home directory under version control, then use something like this:
#
import sys
#
path = '/home/user/upperdirectory/lowerdirectory/projectname/'
if path not in sys.path:
    sys.path.append(path)

from bin import app as application

/home/user/upperdirectory/lowerdirectory/projectname/bin/app.py as follows:

import web

urls = (
        '/', 'index'
        )

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

class index:
    def GET(self):
        greeting = "Hello World"
        return greeting
if __name__ == "__main__":
    app.run()

And when the page loads, I'm getting: Something went wrong :-( Error code: Unhandled Exception

???

Sorry for the slow reply on this one! I think you need to change your WSGI file to be like this:

# +++++++++++ CUSTOM WSGI +++++++++++
# If you have a WSGI file that you want to serve using PythonAnywhere, perhaps
# in your home directory under version control, then use something like this:
#
import sys
#
path = '/home/user/upperdirectory/lowerdirectory/projectname/bin/'
if path not in sys.path:
    sys.path.append(path)

from app import app as application