def write_template(self, **kwargs): """Write out the template with the same name as the class name.""" path = template_path(self.__class__.__name__) template=mako_template(filename=path,lookup=TemplateLookup(directories=[os.path.dirname(__file__)])) text=header() try: text+= template.render(**kwargs) text+=footer() except: text+=exceptions.html_error_template().render() #print values self.response.out.write(text)
def spit(self): try: return mako_template(self.template).render(span_id=self.span_id, graph_type=self.graph_type, x=self.x, y=self.y, data=self.data, axis_labels=self.axis_labels, legend=self.legend, colors=self.colors) except: return exceptions.html_error_template().render()
def post(self): results=[] results_positions=[1,2,3,4,5,6] for i in results_positions: results.append(self.request.get(str(i))) results="".join(results) currentResult=results.replace("2","0").replace("3","1") futureResult=self.answer.replace("3","0").replace("2","1") iChingCurrentResult=str(iChingKeys[currentResult][0]) iChingFutureResult=str(iChingKeys[futureResult][0]) template_path=web_publish.template_path(iChingCurrentResult) #self.response.out.write("SDSSDS") self.response.out.write(mako_template(filename=template_path).render())
def render(self, caller, template, template_vars): """ Renders the template with variable bindings. It's okay to invoke |render| method recursively and |caller| is pushed onto the call stack, which is accessible via |callers_from_first_to_last| method, etc. Args: caller: An object to be pushed onto the call stack. template: A MakoTemplate. template_vars: A dict of template variable bindings. """ assert caller is not None assert isinstance(template, MakoTemplate) assert isinstance(template_vars, dict) self._caller_stack.append(caller) try: mako_template = template.mako_template( pass_key=_MAKO_TEMPLATE_PASS_KEY) mako_context = mako.runtime.Context(self._text_buffer, **template_vars) mako_template.render_context(mako_context) except: # Print stacktrace of template rendering. sys.stderr.write("\n") sys.stderr.write("==== template rendering error ====\n") sys.stderr.write(" * name: {}, type: {}\n".format( _guess_caller_name(self.last_caller), type(self.last_caller))) sys.stderr.write(" * depth: {}, module_id: {}\n".format( len(self._caller_stack), mako_template.module_id)) sys.stderr.write("---- template source ----\n") sys.stderr.write(mako_template.source) # Save the error state at the deepest call. current = self._caller_stack on_error = self._caller_stack_on_error if (len(current) <= len(on_error) and all(current[i] == on_error[i] for i in xrange(len(current)))): pass # Error happened in a deeper caller. else: self._caller_stack_on_error = list(self._caller_stack) raise finally: self._caller_stack.pop()