간단한 웹 앱에서 토네이도를 실행 중입니다. 현재 base.html에 포함되어있는 navbar.html 구성 요소에 로그인 한 사용자 정보를 표시하는 사용자 모듈을 만들려고합니다. python tornado.web.uimodules이 jinja2로 렌더링되지 않습니다.
는 내 설정에서from uimodules import Menu
내가
"ui_modules": {"Menu": Menu}
이 DICT
import tornado.web
class Menu(tornado.web.UIModule):
def render(self):
return '<div>THE MODULE HAS ARRIVED</div>'
그런 다음 내 app.py이 수입 내 메뉴 클래스하는 uimodules.py 파일을 만든 추가
내 이해 이제, 내 전체 애플 리케이션에 메뉴 모듈을 액세스 할 수 있어야하고 내가 추가 할 수 있어야합니다 ...
{% module Menu() %}
...이 모듈을 포함 할 태그. 앱을 실행하면 다음 오류가 발생합니다.
Traceback (most recent call last):
File "/Users/devmode/.virtualenvs/tornado_starter/lib/python3.6/site-packages/tornado/web.py", line 1509, in _execute
result = method(*self.path_args, **self.path_kwargs)
File "app.py", line 69, in get
self.render_template("/pages/index.html", {"login": login, "user": user})
File "app.py", line 60, in render_template
self.write(template.render(**context))
File "/Users/devmode/.virtualenvs/tornado_starter/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "/Users/devmode/.virtualenvs/tornado_starter/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/Users/devmode/.virtualenvs/tornado_starter/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/devmode/.virtualenvs/tornado_starter/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "/Users/devmode/Documents/projects/tornado_starter/myapp/templates/components/navbar.html", line 6, in template
{% module Menu() %}
File "/Users/devmode/.virtualenvs/tornado_starter/lib/python3.6/site-packages/jinja2/environment.py", line 1005, in render
return concat(self.root_render_func(self.new_context(vars)))
File "/Users/devmode/Documents/projects/tornado_starter/myapp/templates/pages/index.html", line 1, in top-level template code
{% extends 'base.html' %}
File "/Users/devmode/Documents/projects/tornado_starter/myapp/templates/base.html", line 17, in top-level template code
{% include 'components/navbar.html' %}
File "/Users/devmode/.virtualenvs/tornado_starter/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/devmode/.virtualenvs/tornado_starter/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "/Users/devmode/Documents/projects/tornado_starter/myapp/templates/components/navbar.html", line 6, in template
{% module Menu() %}
File "/Users/devmode/.virtualenvs/tornado_starter/lib/python3.6/site-packages/jinja2/environment.py", line 497, in _parse
return Parser(self, source, name, encode_filename(filename)).parse()
File "/Users/devmode/.virtualenvs/tornado_starter/lib/python3.6/site-packages/jinja2/parser.py", line 896, in parse
result = nodes.Template(self.subparse(), lineno=1)
File "/Users/devmode/.virtualenvs/tornado_starter/lib/python3.6/site-packages/jinja2/parser.py", line 878, in subparse
rv = self.parse_statement()
File "/Users/devmode/.virtualenvs/tornado_starter/lib/python3.6/site-packages/jinja2/parser.py", line 144, in parse_statement
self.fail_unknown_tag(token.value, token.lineno)
File "/Users/devmode/.virtualenvs/tornado_starter/lib/python3.6/site-packages/jinja2/parser.py", line 97, in fail_unknown_tag
return self._fail_ut_eof(name, self._end_token_stack, lineno)
File "/Users/devmode/.virtualenvs/tornado_starter/lib/python3.6/site-packages/jinja2/parser.py", line 90, in _fail_ut_eof
self.fail(' '.join(message), lineno)
File "/Users/devmode/.virtualenvs/tornado_starter/lib/python3.6/site-packages/jinja2/parser.py", line 59, in fail
raise exc(msg, lineno, self.name, self.filename)
jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'module'.
내가 github에
https://github.com/sunrize531/cherry-forms/blob/master/cherryforms/widgets.py
과 토네이도 문서에서 본 설정을 다음있어
http://www.tornadoweb.org/en/stable/guide/templates.html