I
infidel
I have just recently discovered CherryPy and Kid (many kudos to the
respective developers!) and am tinkering with them to see what I can
come up with.
The application I eventually want to write will eventually require the
python code to call stored procedures in a database which means I'll
need to run CherryPy with a threadPool so individual database calls
don't block the whole server.
I'm not to that point yet, I'm just getting a feel for what is
possible, and I wanted to make sure the following usage of my Kid
template (named "index") is threadsafe:
from cherrypy import cpg
import kid; kid.enable_import()
from infidel.web import index
class Root(object):
@cpg.expose
def index(self, *args, **kwargs):
count = cpg.request.sessionMap.get('count', 0) + 1
cpg.request.sessionMap['count'] = count
template = index.Template(times=count)
return template.serialize(output='html-strict')
if __name__ == '__main__':
cpg.root = Root()
cpg.server.start(configFile = 'web.ini')
Does it matter that I've done the import of index at the module level
instead of inside the index method? The example at the CherryPy
recipes site does this:
from cherrypy import cpg
import kid
class HomePage:
def index(self):
test = kid.Template(file='test.kid')
test.title = "Test Kid Page"
test.lines = ['qwe','asd','zxc']
return test.serialize(output='xhtml')
index.exposed = True
if __name__ == "__main__":
cpg.root = HomePage()
cpg.server.start()
Is there a qualitative difference between what I've done and what the
examle does?
respective developers!) and am tinkering with them to see what I can
come up with.
The application I eventually want to write will eventually require the
python code to call stored procedures in a database which means I'll
need to run CherryPy with a threadPool so individual database calls
don't block the whole server.
I'm not to that point yet, I'm just getting a feel for what is
possible, and I wanted to make sure the following usage of my Kid
template (named "index") is threadsafe:
from cherrypy import cpg
import kid; kid.enable_import()
from infidel.web import index
class Root(object):
@cpg.expose
def index(self, *args, **kwargs):
count = cpg.request.sessionMap.get('count', 0) + 1
cpg.request.sessionMap['count'] = count
template = index.Template(times=count)
return template.serialize(output='html-strict')
if __name__ == '__main__':
cpg.root = Root()
cpg.server.start(configFile = 'web.ini')
Does it matter that I've done the import of index at the module level
instead of inside the index method? The example at the CherryPy
recipes site does this:
from cherrypy import cpg
import kid
class HomePage:
def index(self):
test = kid.Template(file='test.kid')
test.title = "Test Kid Page"
test.lines = ['qwe','asd','zxc']
return test.serialize(output='xhtml')
index.exposed = True
if __name__ == "__main__":
cpg.root = HomePage()
cpg.server.start()
Is there a qualitative difference between what I've done and what the
examle does?