|
Here is the simple "Hello, World!" demo included with the code... (in the demo directory). Ask on the users list for help...
SetHandler python-program PythonHandler jToolkit.web PythonOption jToolkit.module jToolkit.demo.helloworld PythonOption jToolkit.instance HelloWorldConfig PythonDebug On
Note that the line
PythonOption jToolkit.module jToolkit.demo.helloworldspecifies the jToolkit.demo.helloworld module. To specify your own module, replace this with
PythonOption jToolkit.module <your module name>
"""this is a Hello World-style demonstration program of jToolkit""" from jToolkit.web import server from jToolkit.widgets import widgets class HelloWorldServer(server.AppServer): """the Server that serves the Hello World Pages""" def getpage(self, pathwords, session, argdict): """return a page that will be sent to the user""" return widgets.PlainContents("Hello World") class HelloWorldConfig: """the configuration parameters for a hello world server""" serverclass = HelloWorldServer
This expands the "Hello, World!" demo to demonstrate a connection to an Access database, and the displaying of a table on an HTML page. The resulting "helloworld.py" file is listed at the end of this section.
server.DBAppServer inherits from server.AppServer. It has an attribute instance.db, which is a database connection using properties specified in the Config class (jToolkit.instance in the .htaccess file).
To specify the Server as a DBAppServer, add the import
from jToolkit.data import ADOProviderschange the class header to
class HelloWorldServer(server.DBAppServer):and add the following attributes to HelloWorldConfig:
DBTYPE = "access" DBNAME = "d:/temp/jToolkit.mdb" DBHOST = "" DBUSER = "admin" DBPASSWORD = "" DBPROVIDER = ADOProviders.AccessProvider tracefile = "d:/temp/jToolkit.log"where DBTYPE is one of "access","sqlserver", "oracle" or "postgres"
So far, the server will connect to a database, but will not retrieve or display anything from it. This section deals with three objects - dbtable.DBTable, which retirves a table from a database; grid.SimpleGrid, which displays a table as an HTML table; and widgets.Page, which provides the normal encapsulating tags for HTML pages.
"""this is a demonstration program for jToolkit database access""" from jToolkit.web import server from jToolkit.widgets import widgets, grid from jToolkit.data import ADOProviders, dbtable class HelloWorldServer(server.DBAppServer): """the Server that serves the Hello World Pages""" def getpage(self, pathwords, session, argdict): """return a page that will be sent to the user""" testTable = dbtable.DBTable(self.instance.db, "Prices",["id","vendor","product","type","price"],"id",["type","product","vendor"]) testGrid = grid.SimpleGrid(testTable,[("vendor","Vendor",""),("product","Product",""),("type","Type",""),("price","Price","")]) return widgets.Page("Test database connection",[testGrid]) class HelloWorldConfig: """the configuration parameters for a hello world server""" serverclass = HelloWorldServer DBTYPE = "access" DBNAME = "d:/temp/jToolkit.mdb" DBHOST = "" DBUSER = "admin" DBPASSWORD = "" DBPROVIDER = ADOProviders.AccessProvider tracefile = "d:/temp/jToolkit.log"
Other sections on this web page: