Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

missing "pass" in view

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

like image 622
NoviceInPython Avatar asked Apr 03 '14 01:04

NoviceInPython


1 Answers

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.

like image 96
Fury Avatar answered Oct 20 '22 06:10

Fury