使用Flask库在python中进行编码时出现jinja2错误
我不确定错误是什么意思,也不知道如何读取和解决错误
任何人都可以帮助您理解和解决我的错误
错误:jinja2.exceptions.TemplateSyntaxError:意外的“ /”
谢谢
我已经添加了模板的代码段!
{% extends "layout.html" %}
{% block content %}
<div class = "content-section">
<form method="POST" action="">
{{ form.hidden_tags() }}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Join Today</legend>
<div class="form-group">
{{ form.username.label(class = "form-control-label") }}
{{ form.username(class = "form-control form-control-lg") }}
</div>
<div class="form-group">
{{ form.email.label(class = "form-control-label") }}
{{ form.email(class = "form-control form-control-lg") }}
</div>
<div class="form-group">
{{ form.password.label(class = "form-control-label") }}
{{ form.password(class = "form-control form-control-lg") }}
</div>
<div class="form-group">
{{ form.confim_password.label(class = "form-control-label") }}
{{ form.confirm_password(class = "form-control form-control-lg") }}
</div>
</fieldset>
<div class="form-group">
{{ form.submit(class = "btn btn-outline-info")
</div>
</form>
</div>
<div class="border-top pt-3">
<small class="text-muted">
Alredy have an account? <a class="ml-2" href="{{ url_for('login') }}"> Sign In</a>
</small>
</div>
{% endblock %}
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\flask\app.py", line 2309, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\flask\app.py", line 2295, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\flask\app.py", line 1741, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\flask\_compat.py", line 35, in reraise
raise value
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\flask\app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\flask\app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\flask\_compat.py", line 35, in reraise
raise value
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\flask\app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\hemant\PycharmProjects\new\new1.py", line 38, in register
from _pydevd_bundle.pydevd_frame_utils import add_exception_to_frame
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\flask\templating.py", line 134, in render_template
return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\environment.py", line 869, in get_or_select_template
return self.get_template(template_name_or_list, parent, globals)
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\environment.py", line 830, in get_template
return self._load_template(name, self.make_globals(globals))
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\environment.py", line 804, in _load_template
template = self.loader.load(self, name, globals)
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\loaders.py", line 125, in load
code = environment.compile(source, name, filename)
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\environment.py", line 591, in compile
self.handle_exception(exc_info, source_hint=source_hint)
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "C:\Users\hemant\PycharmProjects\new\templates\register.html", line 27, in template
</div>
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\environment.py", line 497, in _parse
return Parser(self, source, name, encode_filename(filename)).parse()
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\parser.py", line 901, in parse
result = nodes.Template(self.subparse(), lineno=1)
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\parser.py", line 883, in subparse
rv = self.parse_statement()
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\parser.py", line 130, in parse_statement
return getattr(self, 'parse_' + self.stream.current.value)()
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\parser.py", line 268, in parse_block
node.body = self.parse_statements(('name:endblock',), drop_needle=True)
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\parser.py", line 165, in parse_statements
result = self.subparse(end_tokens)
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\parser.py", line 875, in subparse
add_data(self.parse_tuple(with_condexpr=True))
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\parser.py", line 620, in parse_tuple
args.append(parse())
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\parser.py", line 432, in parse_expression
return self.parse_condexpr()
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\parser.py", line 437, in parse_condexpr
expr1 = self.parse_or()
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\parser.py", line 450, in parse_or
left = self.parse_and()
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\parser.py", line 459, in parse_and
left = self.parse_not()
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\parser.py", line 470, in parse_not
return self.parse_compare()
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\parser.py", line 480, in parse_compare
ops.append(nodes.Operand(token_type, self.parse_math1()))
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\parser.py", line 496, in parse_math1
left = self.parse_concat()
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\parser.py", line 507, in parse_concat
args = [self.parse_math2()]
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\parser.py", line 517, in parse_math2
left = self.parse_pow()
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\parser.py", line 528, in parse_pow
left = self.parse_unary()
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\parser.py", line 546, in parse_unary
node = self.parse_primary()
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\parser.py", line 583, in parse_primary
self.fail("unexpected '%s'" % describe_token(token), token.lineno)
File "C:\Users\hemant\PycharmProjects\new\venv\lib\site-packages\jinja2\parser.py", line 59, in fail
Open an interactive python shell in this frameraise exc(msg, lineno, self.name, self.filename)
答案 0 :(得分:1)
<div class="form-group">
{{ form.submit(class = "btn btn-outline-info")
</div>
我想这是因为缺少结束标记}} 应该是
<div class="form-group">
{{ form.submit(class = "btn btn-outline-info") }}
</div>