{{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)}}

The above code is showing "missing "pass" in view" error in web2py. Not sure why this error is showing up

有帮助吗?

解决方案

Unlike in real Python, the indentation in a web2py view is only aesthetic. You need to clearly specify where the while block ends by adding pass at its end. Also note that you don't need to constantly close and open the brackets like this, you can escape all the code in only one {{ ... }}.

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

More informations about web2py views here.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top