Search code examples
pythonpython-3.xreturnresponse

When I run my code I'm getting this error: SyntaxError: 'return' outside function


Here is my code snippet.

class IndexResource(Resource):
    @staticmethod
    def get():
        headers ={'Content-Type': 'text/html'}
    return 
make_response(render_template('main.html'), 200, headers)

class AddStudent(Resource):
    @staticmethod
    def get():
        headers = {'Content-Type': 'text/html'}
    return
make_response(render_template('addStudent.html'), 200, headers)

Solution

  • The return statements need to align vertically with the headers line. Not sure what this code should do but this will fix the syntax error.

    class IndexResource(Resource):
        @staticmethod
        def get():
            headers ={'Content-Type': 'text/html'}
            return 
    make_response(render_template('main.html'), 200, headers)
    
    class AddStudent(Resource):
        @staticmethod
        def get():
            headers = {'Content-Type': 'text/html'}
            return
    make_response(render_template('addStudent.html'), 200, headers)