flask模板使用layui前端框架语法冲突

 大致报错如下吧. {{ 很容易冲突. 

File "D:\soft\Python27\lib\site-packages\jinja2\environment.py", line 804, in _load_template
template = self.loader.load(self, name, globals)
File "D:\soft\Python27\lib\site-packages\jinja2\loaders.py", line 125, in load
code = environment.compile(source, name, filename)
File "D:\soft\Python27\lib\site-packages\jinja2\environment.py", line 591, in compile
self.handle_exception(exc_info, source_hint=source_hint)
File "D:\soft\Python27\lib\site-packages\jinja2\environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "d:\work\python\xycdn\templates\rule_add.html", line 58, in template
<option value="1" {{ # if(d.rule_type == 1){}} selected{{ #}}}>鏂囦欢绫诲瀷</option>
TemplateSyntaxError: unexpected char u’#’ at 1794

解决办法:

原始语句: {{# if(d.rule_type == 1){}} selected{{# }}}
修改后: {{" {{# if(d.rule_type == 1){}} selected{{# }}}"}}

其实就是在冲突的代码前后 增加 {{"冲突的代码"}}, 这样就会当作 字符串输出了.

发表评论

您的电子邮箱地址不会被公开。