在视图中缺少"通过"

Nov*_*hon 4 python xml linux web2py

{{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)}}
Run Code Online (Sandbox Code Playgroud)

上面的代码在web2py中显示"丢失"传递"在视图中"错误.不确定为什么会出现此错误

小智 5

与真正的Python不同,web2py视图中的缩进只是美学.您需要while通过pass在结尾添加来清楚地指定块结束的位置.另请注意,您不需要经常关闭并打开这样的括号,您可以只在一个中转义所有代码{{ ... }}.

{{
filename = xmlfile
fh = open(xmlfile, "r")
while True:
    line = fh.readline()
    print(line, end="")
pass
fh.close()
}}
Run Code Online (Sandbox Code Playgroud)

有关web2py视图的更多信息,请点击此处.