# -*- coding: utf-8 -*- from __future__ import print_function import os import codecs import logging from exhibitionist.toolbox import (getLogger, http_handler, JSONRequestHandler, CORSMixin, StaticFileHandler, utf8, HTTPError, xhtml_escape) context = None # get rid of "symbol missing" squiggles in rope logger = getLogger(__name__) # you can use your favorite template engine instead # tornado engine uses "{{context}}" style placeholders, # tmpl=Template(str) to construct templates, # and tmpl.generate(**kwds), to render. from tornado.template import Template PROJECT_NAME = "myAwesomeProject" # This endpoint will be at http://{server_addr}/myAwesomeProject/{objid} # JSONRequestHandler is a subclass of tornado's RequestHandler # with the addition of JSONMixin, providing the write_json() # method. @http_handler(r'/%s/{{objid}}' % PROJECT_NAME,foo='bar') class MainViewHandler(JSONRequestHandler): # any custom kwds argument specified via @http_handler
# -*- coding: utf-8 -*- from __future__ import print_function import codecs import os import logging from exhibitionist.toolbox import ( getLogger, http_handler, JSONRequestHandler, StaticFileHandler, HTTPError) context = None # eliminate "symbol not found" warning logger = getLogger(__name__, logging.INFO) from tornado.template import Template @http_handler("/game") class PingPongView(JSONRequestHandler): """ This view provides the HTML to the client """ def get(self): #note no leading slash, common cause of errors tmpl_file = os.path.join(self.get_template_path(),"index.html") if not(os.path.isdir(self.get_template_path())): self.set_status(500) return self.finish("Template path does not exist") with codecs.open(tmpl_file) as f: self.tmpl = Template(f.read()) static_base=self.static_url("")[:-1] # strip trailing slash result= self.tmpl.generate(static_base=static_base,