From charlesreid1

No edit summary
No edit summary
Line 1: Line 1:
Instructions for deploying Flask as a submodule in a Python module:
=Deploying Flask Web App as Submodule=
 
Instructions for deploying a Flask web app as a submodule in a Python module:


First, your directory structure will look something like this:
First, your directory structure will look something like this:
Line 60: Line 62:


Voila!
Voila!
More information: http://www.plankandwhittle.com/packaging-a-flask-web-app/

Revision as of 19:53, 5 July 2014

Deploying Flask Web App as Submodule

Instructions for deploying a Flask web app as a submodule in a Python module:

First, your directory structure will look something like this:

README.md
setup.py
mymodule/
  __init__.py
  submodule1/
  submodule2/
  webapp/
    __init__.py
    additional_routes.py
    templates/
      [...]
    static/
      [...]

Next, your setup.py file will look something like this:

config = {
    'description': 'My Module',
    'install_requires': ['flask'],
    'packages': ['mymodule','mymodule.submodule1','mymodule.submodule2','mymodule.webapp'],
    'include_package_data' : True,
    'package_data' : {
        'templates' : 'mymodule/webapp/templates/*',
        'static' : 'mymodule/webapp/static/*'
        },
    'scripts': [],
    'name': 'mulch',
    'zip_safe' : False
}

setup(**config)

The key lines here are include_package_data and package_data, which will also install your non-Python template and static files with your module.

Now you can install your module with python setup.py install, and your module is available to use from anywhere.

To create an instance of your module's web app from anywhere, follow these steps:

1. Install the module

2. Import the webapp submodule:

from mymodule.webapp import *

3. Start the webapp:

app.run(debug=True)

Voila!

More information: http://www.plankandwhittle.com/packaging-a-flask-web-app/