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

NoviceInPython
  • 113
  • 1
  • 2
  • 9
  • It looks like you have a ***lot*** of logic in what should be a relatively simple template. –  Apr 03 '14 at 02:26
  • Could you please describe some more detail. I am just sending file name from controller and opening and printing the file in view page. Please suggest how should be my logic? – NoviceInPython Apr 03 '14 at 02:45
  • First, you should try to move more of your logic to the controller. Second, instead of reading each line, just read the whole file. Third, don't use `print()`. Instead of the above, in the controller, just do something like `xml_string = open(filename, 'r').read()`, and in the view include `{{=XML(xml_string)}}`. – Anthony Apr 03 '14 at 03:50

1 Answers1

6

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.

Fury
  • 297
  • 3
  • 7