Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions. And before you ask: It's BSD licensed!
I came across Flask when I was going through the apps from Hasgeek. All their sites are built on Flask. So I thought of giving it a try and I'm not disappointed. Flask is awesome. Minimal, supports Jinja for template managing and all you have to do is work on your app logic. Very less work involved to manage the framework. Here are the quick steps to follow to develop with Flask and deploy the app on an Nginx server -
  1. Install Flask in a vertualenv.
  2. Make a file named your_app_name.py and start building your app.
  3. Test the app locally and when you think you're ready to deploy prepare your server.
  4. Install gcc, python, python-dev, python-virtualenv on your server.
  5. many deployment options, I chose uWSGI. It seemed to have very little footsteps.
  6. Setup the virtualenv and transfer your files to server.
  7. Install uWSGI inside your virtualenv with pip.
    pip install uwsgi
  8. Deploy using uWSGI and Supervisor. Just one thing, instead of using that Symlink method to deploy your site, you might prefer to use these nginx_ensite and nginx_dissite commands.
  9. I made a special executable named nginx_renabsitethat disables the provided site config, reloads the server, then enables new config and again reloads the server -
    nginx_dissite $1
    /etc/init.d/nginx reload
    nginx_ensite $1
    /etc/init.d/nginx reload
    Place this file to /usr/sbin/nginx_renabsiteand you can run it like
    $ nginx_renabsite site_config_filename
  10. Your app should be up and running by now.
  11. Once you make any changes to your app, upload the files to server, then reload Supervisor with supervisorctl.
Things should be fine now. :) P.S. - Here is a fabfile for this deployment. I haven't tried it out yet.

Bibhas Debnath

iambibhas bibhasdn


Published

blog comments powered by Disqus