Take the 2-minute tour ×

Whenever I try to run this script with web.py I get the error message

<type 'exceptions.SyntaxError'> at /hello
'return' outside function (app.py, line 19)

Here is my source:

import web
urls = (
'/hello', 'Index',
'/file_upload_form', 'ThatFile'

app = web.application(urls, globals())

render = web.template.render('templates/', base = "layout")

class ThatFile(object):
    def GET(self):
        return render.file_upload_form()

    def POST(self):
        form = web.input(image = "loc")
        image_o = open(form.image,'r')
        return render.thatfile(image_o = image_o)

class Index(object):

    def GET(self):
        return render.hello_form()

    def POST(self):
        form = web.input(name = "Nobody", greet = None)
        greeting = "%s, %s" % (form.greet, form.name)
        return render.index(greeting = greeting)

if __name__ == "__main__":

I've tried re-indenting the 'returns' but I just get that message.

share|improve this question
check tab/spaces issues by visualising whitespace or Python/Scripts/tabnanny.py –  janislaw Jul 24 '11 at 7:16

1 Answer 1

Your code has mixed tabs and spaces, which is confusing Python. You can choose to use tabs, or you can choose to use spaces (PEP 8 recommends spaces), but you must be consistent.

Check your editor settings to see whether you can tell it to show you tabs and spaces differently (most editors can do this).

share|improve this answer

Your Answer


