Cooperation

There are many ways applications can cooperate:

  • Applications can connect to the same database and thus share tables. It is not necessary that all tables in the database are defined by all applications, but they must be defined by those applications that use them. All applications that use the same table, but one, must define the table with migrate=False.
  • Applications can embed components from other applications using the LOAD helper (described in Chapter 12).
  • Applications can share sessions.
  • Applications can call each other’s actions remotely via XML-RPC.
  • Applications can access each other’s files via the filesystem (assuming they share the same filesystem).
  • Applications can call each other’s actions locally using exec_environment as discussed above.
  • Applications can import each other’s modules using the syntax:
  1. from applications.otherapp.modules import mymodule

or

  1. import applications.otherapp.modules.othermodule
  • Applications can import any module in the PYTHONPATH search path, sys.path.

One app can load the session of another app using the command:

  1. session.connect(request, response, masterapp='appname', db=db)

Here “appname” is the name of the master application, the one that sets the initial session_id in the cookie. db is a database connection to the database that contains the session table (web2py_session). All apps that share sessions must use the same database for session storage.