2010-02-09 53 views
1

我有Mako從預處理器中獲取模板,現在認爲在if語句後有一個'pass' 。Mako認爲我的模板在if語句之後有一個'pass',即使回溯顯示沒有一個

下面是完整的回溯

Error ! 
SyntaxException: (SyntaxError) invalid syntax (, line 1) (u"if ${session['anonymous']}:pass") in file '/.../site/templates/shpaml/views/index.html' at line: 3 char: 1 
1 <p>your anonymous status is ${session['anonymous']}</p> 
2 
3 % if ${session['anonymous']}: 
4 
5 <a href='/login/'>login</a> 
6 
7 % else: 
8 
/.../site/library/mako/pyparser.py, line 37: 
raise exceptions.SyntaxException("(%s) %s (%s)" % (e.__class__.__name__, str(e), repr(code[0:50])), **exception_kwargs) 
/.../site/library/mako/ast.py, line 30: 
expr = pyparser.parse(code.lstrip(), "exec", **exception_kwargs) 
/.../site/library/mako/ast.py, line 82: 
super(PythonFragment, self).__init__(code, **exception_kwargs) 
/.../site/library/mako/parsetree.py, line 69: 
code = ast.PythonFragment(text, **self.exception_kwargs) 
/.../site/library/mako/lexer.py, line 94: 
node = nodecls(*args, **kwargs) 
/.../site/library/mako/lexer.py, line 313: 
self.append_node(parsetree.ControlLine, keyword, isend, self.escape_code(text)) 
/.../site/library/mako/lexer.py, line 152: 
if self.match_control_line(): 
/.../site/library/mako/template.py, line 257: 
node = lexer.parse() 
/.../site/library/mako/template.py, line 93: 
(code, module) = _compile_text(self, file(filename).read(), filename) 
/.../site/library/mako/lookup.py, line 127: 
self.__collection[uri] = Template(uri=uri, filename=posixpath.normpath(filename), lookup=self, module_filename=(self.modulename_callable is not None and self.modulename_callable(filename, uri) or None), **self.template_args) 
/.../site/library/mako/lookup.py, line 85: 
return self.__load(srcfile, uri) 
/.../site/library/templates/__init__.py, line 25: 
template = lookup_map[type].get_template(template_name) 

爲什麼會回溯節目通不過沒有表現出來的追溯來源?最重要的是,它表示錯誤的行號。 $ {session ['anonymous']}在第1行返回True(如果我刪除語法錯誤)。所以這沒有任何問題。

回答

1

好了,這是那些帶着痛苦的日子找出這麼簡單的東西的尷尬情形之一:

它需要的是

if session['anonymous']: 
相關問題