From ef186b8d44d1333d970e95a135f415792d57787a Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 25 Jan 2021 12:03:19 +0800 Subject: [PATCH] bugfix --- ahserver/baseProcessor.py | 8 ++++---- ahserver/myTE.py | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ahserver/baseProcessor.py b/ahserver/baseProcessor.py index 07b1aa4..52aba68 100644 --- a/ahserver/baseProcessor.py +++ b/ahserver/baseProcessor.py @@ -5,8 +5,6 @@ import codecs from aiohttp.web_request import Request from aiohttp.web_response import Response, StreamResponse -from jinja2 import Template,Environment,BaseLoader - from appPublic.jsonConfig import getConfig from appPublic.dictObject import DictObject from appPublic.folderUtils import listFile @@ -64,7 +62,9 @@ class BaseProcessor: self.run_ns.update(g) self.run_ns.update(self.resource.y_env) self.run_ns['request'] = request - self.run_ns['params_kw'] = await self.run_ns['request2ns']() + kw = await self.run_ns['request2ns']() + self.run_ns['params_kw'] = kw + self.run_ns.update(kw) self.run_ns['ref_real_path'] = self.path async def execute(self,request): @@ -108,7 +108,7 @@ class TemplateProcessor(BaseProcessor): ns = self.run_ns ns.update(params) te = self.run_ns['tmpl_engine'] - return te.render(url,**ns) + return await te.render(url,**ns) async def datahandle(self,request): self.content = await self.path_call(request) diff --git a/ahserver/myTE.py b/ahserver/myTE.py index 052c8fc..ca8e854 100644 --- a/ahserver/myTE.py +++ b/ahserver/myTE.py @@ -34,16 +34,16 @@ class TmplLoader(BaseLoader, TmplUrl2File): class TemplateEngine(Environment): def __init__(self,loader=None): - Environment.__init__(self,loader=loader) + Environment.__init__(self,loader=loader, enable_async=True) self.urlpaths = {} self.loader = loader def join_path(self,template: str, parent: str): return self.loader.join_path(template, parent) - def render(self,___name: str, **globals): + async def render(self,___name: str, **globals): t = self.get_template(___name,globals=globals) - return t.render(globals) + return await t.render_async(globals) def setupTemplateEngine(): config = getConfig()