Мне нужно отобразить строковый шаблон, который имеет теги, начинающиеся с цифры, и я получаю следующее исключение: jinja2.exceptions.TemplateSyntaxError: ожидаемый токен «конец оператора печати», полученный «d_printer_name»
>>> jinja2.__version__
'2.10.3'
>>> flask.__version__
'1.1.1'
hello.py :
from flask import Flask, render_template_string
app = Flask(__name__)
@app.route("/")
def hello():
render_data = { "3d_printer_name": "A name for printer"}
rendered = render_template_string("Name: {{ 3d_printer_name}}.", **render_data)
return rendered
Я также пытаюсь поставить тег {% autoescape false%}, но проблема все еще есть.
Любая помощь приветствуется!
Это обратная связь:
[2019-11-07 14:11:50,609] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
File "/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/mgieco/Developments/tmp/flask_render/hello.py", line 8, in hello
decoration = render_template_string("Name: {{ 3d_printer_name}}.", **decoration_data)
File "/site-packages/flask/templating.py", line 155, in render_template_string
return _render(ctx.app.jinja_env.from_string(source), context, ctx.app)
File "/site-packages/jinja2/environment.py", line 880, in from_string
return cls.from_code(self, self.compile(source), globals, None)
File "/site-packages/jinja2/environment.py", line 591, in compile
self.handle_exception(exc_info, source_hint=source_hint)
File "/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "<unknown>", line 1, in template
File "/site-packages/jinja2/environment.py", line 497, in _parse
return Parser(self, source, name, encode_filename(filename)).parse()
File "/site-packages/jinja2/parser.py", line 901, in parse
result = nodes.Template(self.subparse(), lineno=1)
File "/site-packages/jinja2/parser.py", line 876, in subparse
self.stream.expect('variable_end')
File "/site-packages/jinja2/lexer.py", line 384, in expect
self.name, self.filename)
jinja2.exceptions.TemplateSyntaxError: expected token 'end of print statement', got 'd_printer_name'
127.0.0.1 - - [07/Nov/2019 14:11:50] "GET / HTTP/1.1" 500 -