Flask: Difference between revisions
From charlesreid1
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
=Deploying Flask Web App as Submodule= | =Packaging Flask Apps= | ||
==Deploying Flask Web App as Submodule== | |||
Instructions for deploying a Flask web app as a submodule in a Python module: | Instructions for deploying a Flask web app as a submodule in a Python module: | ||
Revision as of 19:53, 5 July 2014
Packaging Flask Apps
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/