Version 161 (modified by Dominic König, 13 years ago) ( diff )


Developer Guidelines

Development Process

Development Enviroment


User Interface

Other Resources

  • Tips - useful links to explore


  • Android - Developer Guidelines for the Android client


Indentation matters (use 4 spaces instead of Tabs)

More details at: DeveloperGuidelinesCodeConventions


This is an MVC environment (like Rails & Django. Django polls tutorial conversion course).

Web2Py can work at several different levels of abstraction.
The Sahana Eden framework (S3) is built on Web2Py's Auth/Crud classes in (with some remnants of the older T2), however sometimes we need more control therefore need to drop down a level or two.

Recommend using the CLI to try out code snippets in the Web2Py environment (gluon, Model):

python -S eden -M

Can execute a controller to be able to access its functions using:

execfile("applications/eden/controllers/", globals())

Web2Py can be extended through Plugins & also has a recipes site.


This tutorial was given at SahanaCamp 1.1 in Taiwan:


Defines databases in: /models/

The Models are loaded 1st within Web2Py processing, before the controllers.
So you can import any global modules/set any global variables here.
The Models are imported in alphabetical order, so we load the files which other modules depend on 1st, hence naming them appropriately:,,,, etc


Python functions in /controllers/

   def list_records():
       items =
       return dict(items=items)


HTML/Javascript templates in /views/module/function.html

  • these are normal HTML/JS files with the ability to add in Python code (e.g. variables) surrounded by brackets: {{ interpreted python here }}
  • there should be an .html file available for each function in the module (name normally being the same as the function)
  • these normally inherit from views/layout.html which also includes the JavaScript from views/*_ajax.html
  • if there is no view defined then a default view will be displayed, which will show the values of all the data it can see, but not be formatted nicely

Static CSS/Javascript files are stored in /static


  • S3 includes a cross-browser debug utility (only shows up when ?debug=1):
    s3_debug('message', value);

All global variables should be in the S3 namespace:

The Module Pattern should be used to protect private variables:


Browsers default to only downloading 2 files from the same origin at a time, so many files is very slow on high latency links.

We therefore consolidate into fewer, larger files when running in Production mode.

Since GIS is a specialised app which requires many files, it's JS is loaded separately when required.

The build script is static/scripts/tools/

There is also a convenience wrapper for Windows to run this & also move results into their respective locations: static/scripts/tools/build.cmd

Need to remove the '@' from '@requires' in header of /static/scripts/S3/jquery.form.js as we need to compress this without the main file.

Our build process is based on the one used by MapFish (which is built on the one used by OpenLayers)

ToDo: Investigate using other options instead:

ToDo: Investigate using LabJS to download/execute scripts asynchronously:

Note: See TracWiki for help on using the wiki.