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.

Changes between Initial Version and Version 1 of DevelopmentServer


Ignore:
Timestamp:
Jun 24, 2008, 2:20:21 PM (16 years ago)
Author:
cmlenz
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DevelopmentServer

    v1 v1  
     1= Development Server =
     2
     3Diva comes with a couple of simple shortcuts for running your application using the `WSGIServer` from the Python standalone library.
     4
     5Assuming you have an `Application` subclass (see ApplicationArchitecture), for example:
     6
     7{{{
     8#!pycon
     9>>> from diva.core import Application
     10>>> class MyApp(Application):
     11...     pass
     12}}}
     13
     14You can then run that application using the development server as follows, directly from the Python shell:
     15
     16{{{
     17#!pycon
     18>>> import logging
     19>>> from diva.server import serve
     20>>> serve(MyApp(), log_level=logging.DEBUG)
     21[INFO] diva.server: Serving <__main__.MyApp object at 0x10f63f0> on 127.0.0.1:8080
     22}}}
     23
     24== Command-Line Interface ==
     25
     26It's also simple to enable your application to be run from the command-line, as shown in the following script:
     27
     28{{{
     29#!python
     30import os
     31from diva.core import Application
     32from diva.server import main
     33
     34class MyApp(Application):
     35    pass
     36
     37if __name__ == '__main__':
     38    main(app)
     39}}}
     40
     41Now running that script will automatically launch a simple command-line interface complete with options:
     42
     43{{{
     44$ python myapp.py --help
     45Usage: myapp.py [options]
     46
     47Options:
     48  -h, --help            show this help message and exit
     49  -b HOST, --host=HOST  hostname or IP address to bind to (default 127.0.0.1)
     50  -p PORT, --port=PORT  port number to listen to (default 8080)
     51  -r, --auto-reload     automatically restart after code changes (default
     52                        True)
     53  -v, --verbose         print as much as possible
     54  -q, --quiet           print as little as possible
     55
     56}}}