BlackEagle
BlackEagle

Reputation: 143

Unable to run waitress flask app on windows using command line

I am trying to run waitress WSGI on windows for a sample flask app but it is not working and getting an error

It had these arguments:
1. module 'myapp' has no attribute 'create_app'

I am using

waitress-serve --port=80 --call  "myapp:create_app"

The below are my 2 files in the same directory

myapp.py

from flask import Flask
app = Flask(__name__)

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

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

create_app.py

from myapp import app

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

Upvotes: 1

Views: 4712

Answers (1)

Kris
Kris

Reputation: 8868

The documentation for waitress says this

waitress-serve [OPTS] MODULE:OBJECT

Your MODULE:OBJECT is given as "myapp:create_app" which means look for module myapp and find the name/object create_app in that.

Looking in the myapp.py , there is no create_app object/method in that. So you need to change the myapp.py like

from flask import Flask

def create_app():
    app = Flask(__name__)

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

    return app

Then it works!

Upvotes: 3

Related Questions