Search code examples
azureiisflaskazure-web-roles

Azure WebRole + Flask: AttributeError: 'module' object has no attribute 'wsgi_app'


Unlike Azure Flask Deployment - WSGI Interface problem, deploying Flask app to Azure Web Role throws a following problem.

AttributeError: 'module' object has no attribute 'wsgi_app'

What is this error?


Solution

  • I got it finally.

    The startup .py file has to define wsgi_app after the Flask app definition.

    app = Flask(__name__)
    
    # define for IIS module registration.
    wsgi_app = app.wsgi_app
    
    if __name__ == '__main__':
        app.run()
    

    And also, {StartupModule}.wsgi_app is defined in Project properties > Web > WSGI Handler.

    To shorten trial-and-error time, it would be good to start with newly created Azure WebRole Python project template.

    Whooa. spent a whole day.