close Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Version 4 (modified by cmlenz, 13 years ago) (diff)


Development Server

Diva comes with a couple of simple shortcuts for running your application using the WSGIServer from the Python standalone library.

Assuming you have an Application subclass (see ApplicationObject), for example:

>>> from diva.core import Application
>>> class MyApp(Application):
...     pass

You can then run that application using the development server as follows, directly from the Python shell:

>>> import logging
>>> from diva.server import serve
>>> serve(MyApp(), log_level=logging.DEBUG)
[INFO] diva.server: Serving <__main__.MyApp object at 0x10f63f0> on

Command-Line Interface

It's also simple to enable your application to be run from the command-line, as shown in the following script:

import os
from diva.core import Application
from diva.server import main

class MyApp(Application):

if __name__ == '__main__':

Now running that script will automatically launch a simple command-line interface complete with options:

$ python --help
Usage: [options]

  -h, --help            show this help message and exit
  -b HOST, --host=HOST  hostname or IP address to bind to (default
  -p PORT, --port=PORT  port number to listen to (default 8080)
  -r, --auto-reload     automatically restart after code changes (default
  -v, --verbose         print as much as possible
  -q, --quiet           print as little as possible

Automatic Reloading

When the command-line interface is used, automatic restarting of the server can be enabled using the --auto-reload (or -r) option. This will cause the framework to look for changes to any loaded Python modules, as well as a couple of other files such as routing configuration files and translation catalogs. Whenever a change is detected the complete server process is restarted. Note that this will sometimes cause a short delay until the server is available again.

Applications can add their own files to the list of watched files using the watch_file() function.

API Documentation

Error: Macro PythonDoc(trunk, diva.server) failed
Unsupported version control system "svn": No module named svn

Attachments (1)

Download all attachments as: .zip