loading...

Simplest way to deploy a Flask app

pbouillon profile image Pierre Bouillon ・1 min read

Hi !

I wrote a simple Flask app using flask and sqlalchemy which run pretty well on localhost but I would like to deploy it. The problem is that I don't have any clue on how to deploy it..

Could somebody explain me the simplest way to deploy my Flask app?

Thanks !

EDIT
I'm on Windows

Discussion

markdown guide
 

Mitch,

Thanks much for posting this detailed guideline. By any chance are you planning to do an updated blog post ? I attempted to follow - your blog post to the very last detail, and could not get the Flask App deployed.

There were a couple of errors specific to apache - and after a LOT of research later, it was just a dead end for me.

Thanks
Sandeep.

 

I don't think he'll receive a notification since it's not a reply to his comment, let me tag him ! @mitchjacksontech

 

Sandeep, have you been able to solve the problem? If not and you're interested in revisiting, perhaps I can help with the apache errors. You can find my e-mail address on my dev.to profile

 

Flask's own documentation give you a few deployment options.

You can try Heroku's free plan:

 

I am successfully using the simple Twisted Web server on Windows for Flask web sites.
Are others also successfully using Twisted on Windows, to validate that configuration?

new_app.py
if name == "main":
reactor_args = {}

def run_twisted_wsgi():
    from twisted.internet import reactor
    from twisted.web.server import Site
    from twisted.web.wsgi import WSGIResource

    resource = WSGIResource(reactor, reactor.getThreadPool(), app)
    site = Site(resource)
    reactor.listenTCP(5000, site)
    reactor.run(**reactor_args)

if app.debug:
    # Disable twisted signal handlers in development only.
    reactor_args['installSignalHandlers'] = 0
    # Turn on auto reload.
    import werkzeug.serving
    run_twisted_wsgi = werkzeug.serving.run_with_reloader(run_twisted_wsgi)

run_twisted_wsgi()

old_app.py
if name == "main":
app.run()

 

I had the same problem when I deployed my first Flask app. To approach the problem, I created a very simple small application, and worked through the kinks until I got it deployed in a way I was happy with. Only then did I move to deploying my full application.

I documented the process in this blog post. Perhaps it will be some help.

 

You might also take a look at Netlify. It's a well documented tool for deploying side projects quickly and even beyond:
netlify.com/docs/#python

 

You will need a WSGI server. Have a look at this tutorial. It shows you how to deploy a flask app using Nginx and uwsgi.

 

In case you want to deploy Flask app to azure, you can follow along with the tutorial here bit.ly/2lCnxMx