waitress command line returning "Malformed Application" when deploying flask web app

I'm attempting to deploy a simple web app, and I'm using command line waitress-serve --call command. But every time, the command immediately returns 1. Malformed application 'name_of_project_here'.

Here's my flask web app in python:

from flask import Flask, render_template
app = Flask(__name__)

@app.route('/')
def index():
    return render_template('base.html')

if __name__ == '__main__':
   app.run(debug = True)

and the command I run is just

waitress-serve --call "name_of_project"

I did try looking through the documentation, and I found where the error occurs, but couldn't find an explanation of why it's occurring. What does malformed application mean?


Solution 1:

Minimal working example:

If you put code in file main.py

from flask import Flask

def create_app():
    app = Flask(__name__)

    @app.route('/')
    def index():
        return "Hello World!"

    return app

if __name__ == '__main__':
    app = create_app()
    app.run()    

then you can run it as

waitress-serve --call "main:create_app"

So "name_of_project" has to be "filename:function_name" which creates Flask() instance.

It can't be any text. And if you forget : then you may see "Malformed application"

Solution 2:

when defining your appname and the function that initialize your app with : dont put them into quotes('')