Anatomy of a Divio Cloud addon¶

Basic file structure¶

For an addon “Susan Example Application”:

  1. addons-dev/
  2. susan-example-application/
  3. addon.json
  4. LICENSE
  5. MANIFEST.in
  6. README.rst
  7. setup.py
  8. susan_example_application/
  9. __init__.py

aldryn_config.py¶

All addons have an aldryn_config.py file that takes care of settings, whichare then loaded into settings.py.

This means that any settings you need to apply in a project can’t simply beapplied in your settings.py if an addon also needs access to them.

For example, nearly every addon will add a package, or sometimes several, toINSTALLED_APPS. If you were to assign do INSTALLED_APPS = […] in theusual way, you would overwrite the existing assignments and break the project.That’s why our settings.py uses:

  1. INSTALLED_APPS.extend([
  2. # add your project specific apps here
  3. ])

The same goes for middleware, and other settings.

aldryn_config.py is loaded into the Django project at run-time, so anychanges are picked up when and reloaded automatically when developing.

aldryn_config.py is an ideal place to check for environment variables thatshould be converted into Django settings.

See Application configuration with aldryn_config.py.

addon.json¶

A metadata file.

  1. {
  2. "package-name": "susan-example-application",
  3. "installed-apps": [
  4. "susan_example_application"
  5. ]
  6. }

setup.py¶

setup.py will be generated by the Control Panel on the basis of theinformation you provided when you first created it there. The lines highlightedbelow are those that will be specific to your addon:

  1. # -*- coding: utf-8 -*-
  2. from setuptools import setup, find_packages
  3. from susan_example_application import __version__
  4.  
  5.  
  6. setup(
  7. name='susan-example-application',
  8. version=__version__,
  9. description=open('README.rst').read(),
  10. author='Susan',
  11. author_email='[[email protected]](http://docs.divio.com/cdn-cgi/l/email-protection)',
  12. packages=find_packages(),
  13. platforms=['OS Independent'],
  14. install_requires=["example_application==1.8.3"],
  15. include_package_data=True,
  16. zip_safe=False,
  17. )

原文: http://docs.divio.com/en/latest/background/anatomy-addon.html