def test(): with open("./example_result.html", "r") as f: example_result = f.read() title = "test case" obj = Obj() numbers = [1, 2, 3, 4, 5, 6] dictionary = {"dict": "Tis is dict"} render_result = render("./example.html", title=title, obj=obj, numbers=numbers, dict=dictionary) render_result = render_result.replace(" ", "").replace("\t", "").replace(" ", "").replace("\n", "") render_result = utf8(render_result) example_result = example_result.replace(" ", "").replace("\t", "").replace(" ", "").replace("\n", "") if render_result != example_result: print type(example_result), type(render_result) print example_result print render_result assert "render error" with open("./example.html", "r") as f: example_html = f.read() render_result = render_string(example_html, title=title, obj=obj, numbers=numbers, dict=dictionary) render_result = render_result.replace(" ", "").replace("\t", "").replace(" ", "").replace("\n", "") render_result = utf8(render_result) example_result = example_result.replace(" ", "").replace("\t", "").replace(" ", "").replace("\n", "") if render_result != example_result: print type(example_result), type(render_result) print example_result print render_result assert "render_string error"
def render(self, template_path, **kwargs): """ customize your HTTPResponse web page use template :param template_path: template path :param kwargs: parameters :return: html formatted string """ static_path = self.__settings.get("template", ".") template_path = static_path + template_path return render(template_path, **kwargs)
def render(self, template_path, **kwargs): """render a template :param template_path: template's relative path :param kwargs: params used in template :return: a tuple contains http message, status, status message """ root_path = self.__settings.get("template", ".") template_path = root_path + template_path return render(template_path, **kwargs), HttpStatus.SUCCESS, HttpStatusMsg.SUCCESS, self
def render(self, template_path, **kwargs): """render a template :param template_path: template's relative path :param kwargs: params used in template :return: a tuple contains http message, status, status message """ root_path = self.__settings.get("template", ".") template_path = root_path + template_path response = render(template_path, **kwargs) if not PY3: out = io.BytesIO() with gzip.GzipFile(fileobj=out, mode="w") as f: f.write(response) response = out.getvalue() self.set_header({"Content-Encoding": "gzip"}) return response, HttpStatus.SUCCESS, HttpStatusMsg.SUCCESS, self
def render(self, template_path, **kwargs): root_path = self.__settings.get("template", ".") template_path = root_path + template_path return render(template_path, **kwargs)