Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 540
Amin Avatar asked Oct 14 '25 17:10

Amin


2 Answers

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"

like image 120
furas Avatar answered Oct 17 '25 12:10

furas


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

like image 41
Akatsuki Kojou Avatar answered Oct 17 '25 12:10

Akatsuki Kojou



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!