Version 3 (modified by cmlenz, 16 years ago) (diff) |
---|
Application Object
There can only be one instance of a diva.core.Application per Python interpreter. That is because the application is in many places accessed via the app singleton, which provides thread-local access to the application context.
Usually a specific application will define a subclass of diva.core.Application that is explicitly instantiated at startup:
>>> from diva.core import Application >>> >>> class MyApp(Application): ... pass ... >>> myapp = MyApp()
After this point, you'll be able to access the singleton instance of the application using a simple import:
>>> from diva import app >>> app <diva.ApplicationProxy object at …>
This application proxy forwards all operations to the actual application class. The application class has a ctxt property that provides access to various thread-local objects, such as the current HTTP request.
Initialization with a Configuration File
The Application provides a convenience factory function that lets you instantiate an application using an INI-style configuration file.
For example, assume the following configuration is stored in conf/myapp.ini:
[app] locale = en_US timezone = UTC doctype = html-strict debug = true
Now you can easily instantiate your application using the configure() class method:
>>> from mypkg import MyApp >>> myapp = MyApp.configure('conf/myapp.ini')
See ConfigOptions for information on the configuration options that are available by default, although you can of course always add your own.
API Documentation