<br><br><div><span class="gmail_quote">On 2/22/06, <b class="gmail_sendername">Matt Helm</b> <<a href="mailto:code.name.eric@gmail.com">code.name.eric@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On 2/21/06, Graeme Glass wrote:<br>> Would you mind posting some sample code, for refrence?<br>> Many thanks.<br><br>class Resource(resource.Resource):<br><br> def render(self, request):<br><br> def cheeto(r):
<br> request.write(r.__str__())<br> request.finish()<br><br> def cherr(r):<br> request.write("Bang!")<br> request.write(str(r))<br> request.finish()<br><br>
d_cheeto = threads.deferToThread(Template, file="alf.tmpl", searchList =<br> slist)<br> d_cheeto.addCallback(cheeto)<br> d_cheeto.addErrback(cherr)<br><br> return server.NOT_DONE_YET<br>
<br>resource = Resource()<br><br>_______________________________________________<br>Twisted-web mailing list<br><a href="mailto:Twisted-web@twistedmatrix.com">Twisted-web@twistedmatrix.com</a><br><a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web">
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web</a><br></blockquote></div>webexp.py<br>
--------------------------------------------<br>
from twisted.application import internet, service<br>
from twisted.web import static, server, script<br>
import CheetahMapper<br>
<br>
root = static.File("./")<br>
root.indexNames=['index.cht']<br>
root.ignoreExt(".cht")<br>
root.processors = {'.cht': CheetahMapper.CheetahResource}<br>
application = service.Application('web')<br>
sc = service.IServiceCollection(application)<br>
site = server.Site(root)<br>
i = internet.TCPServer(8888, site)<br>
i.setServiceParent(sc)<br>
<br>
CheetahMapper.py<br>
------------------------------------------------<br>
from twisted.web import resource, server<br>
from Cheetah.Template import Template<br>
<br>
<br>
class CheetahResource(resource.Resource):<br>
isLeaf = 1<br>
<br>
def __init__(self, filename, registry):<br>
self.filename = filename<br>
self.registry = registry<br>
<br>
def render(self, request):<br>
tmplt = Template.compile(file=self.filename)<br>
inst=tmplt()<br>
request.write(str(inst))<br>
request.finish()<br>
return server.NOT_DONE_YET<br>
<br>
time.cht<br>
------------------------------------------------------<br>
#import time<br>
<html><br>
<head><br>
<title>Time Example</title><br>
</head><br>
<body><br>
It is $time.strftime("%I:%M %p").<br>
<br><br>
Date is $time.strftime("%A, %B %D, %Y").<br>
</body><br>
</html><br>
-----------------------------------------------------------------------<br>
Not the best code in the world, but it has been useful for me for just throwing together quick pages and experimenting.<br>
<br>
ToddB<br>