Question

How do I set up the .wsgi file and apache configuration to deploy on a Large Flask Application on to my droplet?

I have created a Flask Application based on the Large Application Structure in Miguel Grinberg’s Flask Web Development Book. I have followed the tutorial in how-to-deploy-a-flask-application-on-an-ubuntu-vps and have managed to deploy a single file Flask application on my server. What changes/ modifications do I have to implement to my .wsgi file and apache config to be able to host Large Structured applications?

Subscribe
Share

there are some good ideas in http://www.enigmeta.com/2012/08/16/starting-flask/. The following were found to be in error, but still a good deployment model.

add *.py[cod] to the .gitignore file, actually maybe suggest picking up template from https://github.com/github/gitignore/blob/master/Python.gitignore

references to git@github.com:USERNAME/helloflask.git didn’t seem to work for me. I had to use https://github.com/USERNAME/helloflask.git, for git remote add origin git@github.com:USERNAME/helloflask.git and git clone git@github.com:USERNAME/helloflask.git

the fabfile.py needed some changes. Here is what worked for me. Note change on source bin/activate line, had to have pip install in same run command

from fabric.api import env, run, cd

USERNAME = 'root'
SERVER = 'helloflask.example.org'
APP_NAME = 'helloflask'
PROJECT_DIR = '/var/www/%s/%s' % (SERVER, APP_NAME)
WSGI_SCRIPT = 'application.wsgi'

env.hosts = ["%s@%s" % (USERNAME, SERVER)]

def deploy():
    with cd(PROJECT_DIR):
        run('git pull')
        run('source bin/activate; pip install -r requirements.txt')
        run('touch %s' % WSGI_SCRIPT)

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

This question was answered by @lking:

there are some good ideas in http://www.enigmeta.com/2012/08/16/starting-flask/. The following were found to be in error, but still a good deployment model.

add *.py[cod] to the .gitignore file, actually maybe suggest picking up template from https://github.com/github/gitignore/blob/master/Python.gitignore

references to git@github.com:USERNAME/helloflask.git didn’t seem to work for me. I had to use https://github.com/USERNAME/helloflask.git, for git remote add origin git@github.com:USERNAME/helloflask.git and git clone git@github.com:USERNAME/helloflask.git

the fabfile.py needed some changes. Here is what worked for me. Note change on source bin/activate line, had to have pip install in same run command

from fabric.api import env, run, cd

USERNAME = 'root'
SERVER = 'helloflask.example.org'
APP_NAME = 'helloflask'
PROJECT_DIR = '/var/www/%s/%s' % (SERVER, APP_NAME)
WSGI_SCRIPT = 'application.wsgi'

env.hosts = ["%s@%s" % (USERNAME, SERVER)]

def deploy():
   with cd(PROJECT_DIR):
       run('git pull')
       run('source bin/activate; pip install -r requirements.txt')
       run('touch %s' % WSGI_SCRIPT)

View the original comment