{{extend 'layout.html'}}
{{import xml.etree.ElementTree as ET}}
<h1>
This is a Stations detail page
</h1>
{{filename = xmlfile}}
{{fh = open(filename, "r")}}
{{while True:}}
{{line = fh.readline()}}
{{print(line, end="")}}
{{fh.close()}}
{{=BEAUTIFY(response._vars)}}
上面的代码显示&#34;缺少&#34;传递&#34;在视图&#34; web2py中的错误。不确定为什么会出现此错误
答案 0 :(得分:5)
与真正的Python不同,web2py视图中的缩进只是美学。您需要通过在其末尾添加while
来明确指定pass
块结束的位置。另请注意,您不需要经常关闭并打开这样的括号,您只能在一个{{ ... }}
中转义所有代码。
{{
filename = xmlfile
fh = open(xmlfile, "r")
while True:
line = fh.readline()
print(line, end="")
pass
fh.close()
}}