from twisted.web.resource import Resource from twisted.web import server class AnExampleResource(Resource): def render_GET(self, request): ... resource = AnExampleResource()
from twisted.web.resource import Resource from twisted.web import serverThe rpy script must then implement a subclass of Resource that serves the desired content:
class AnExampleResource(Resource): def render_GET(self, request): request.write(""" <h1>This works</h1> """) request.finish() return server.NOT_DONE_YETFinally, the rpy script must end by defining an instance of the class as a variable called resource:
resource = AnExampleResource()If a restriction is set in the rtwebserver parameter-file valid_ip_addresses table, the request will have the member request.rstrict set to the contents of the restriction string (see legit_ip(3) for further details).
Then construct an rtwebserver.pf file with the following contents:% cat anexampleresource.rpy from twisted.web.resource import Resource from twisted.web import server import rtwebserver.config as config class AnExampleResource(Resource): def render_GET(self, request): dbname = config.sitedict['siteconfig']['databases']['antelope_demo'] request.write("<h1>Demo database name is %s</h1>" % dbname) request.finish() return server.NOT_DONE_YET resource = AnExampleResource() %
Then run rtwebserver as follows:% cat rtwebserver.pf port 8008 site &Arr{ pythonpaths &Tbl{ } siteconfig &Arr{ databases &Arr{ antelope_demo /opt/antelope/data/db/demo/demo } } pages &Arr{ index rpy:anexampleresource.rpy index } } %
% rtwebserverThe name of the configured database should be available via a web link to the localmachine
http://localhost:8008
rtwebserver(1), http://twistedmatrix.com
Kent Lindquist