4

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?

Amin
  • 908
  • 1
  • 11
  • 23

2 Answers2

8

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"

furas
  • 134,197
  • 12
  • 106
  • 148
  • Thanks, this worked! I had a Flask folder I was using in the place of ```"name_of_project"``` since it linked to other python files, but I guess it should have been just the name of the main application file. – Amin Aug 22 '19 at 03:48
  • it has to be name of main file and `:` with name of function which returns `Flask` instance. It can't be only name of main file. – furas Aug 22 '19 at 08:45
1

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

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30843887) – Register Sole Jan 21 '22 at 03:24