# -*- coding: utf-8 -*
import os, sys
from twisted.application import internet
from twisted.web.resource import Resource
from twisted.web import server
from twisted.internet import reactor
import txtemplate
TEMPLATE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)),"templates")
class ThreadResource(Resource):
def __init__(self):
resource.Resource.__init__(self)
self.loader = txtemplate.Jinja2TemplateLoader(TEMPLATE_DIR)
def getChild(self, name, request):
return self
def render_GET(self, request):
template_name = "base.html"
template = self.loader.load(template_name)
context = {"greeting": "Enter"}
def cb(content):
request.write(content)
request.setResponseCode(200)
request.finish()
d = template.render(**context)
d.addCallback(cb)
return server.NOT_DONE_YET
site = server.Site(ThreadResource())
reactor.listenTCP(8888, site)
reactor.run()