To get underway, we need a shell of a web application where we can start filling in the details. We previously used CherryPy (http://cherrypy.org) to build a simple web app, so let's use that to kick things off.
import cherrypy import os import ctx from springpython.context import ApplicationContext if __name__ == '__main__': cherrypy.config.update({'server.socket_port': 8009}) applicationContext = ApplicationContext(ctx.SpringBankAppContext()) cherrypy.tree.mount( applicationContext.get_object("view"), '/', config=None) cherrypy.engine.start() cherrypy.engine.block()
You may notice that, it is looking inside package ctx
for SpringBankAppContext
to find the view object.
from springpython.config import PythonConfig, Object from app import * class SpringBankAppContext(PythonConfig): def __init__(self): PythonConfig.__init__(self) @Object def view(self): return SpringBankView()
This is the simplest container possible. We basically have one object, view
,
which returns an instance of SpringBankView
. Later on, if we need other
injected objects or features, we can easily update this confi guration.
import cherrypy class SpringBankView(object): @cherrypy.expose def index(self, args=None): return """ Welcome to SpringBank! """
This is our starting position of a web application. From here, we will spend the rest of the chapter tackling the features we just described.