| 1 | = Development Server = |
| 2 | |
| 3 | Diva comes with a couple of simple shortcuts for running your application using the `WSGIServer` from the Python standalone library. |
| 4 | |
| 5 | Assuming 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 | |
| 14 | You 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 | |
| 26 | It's also simple to enable your application to be run from the command-line, as shown in the following script: |
| 27 | |
| 28 | {{{ |
| 29 | #!python |
| 30 | import os |
| 31 | from diva.core import Application |
| 32 | from diva.server import main |
| 33 | |
| 34 | class MyApp(Application): |
| 35 | pass |
| 36 | |
| 37 | if __name__ == '__main__': |
| 38 | main(app) |
| 39 | }}} |
| 40 | |
| 41 | Now running that script will automatically launch a simple command-line interface complete with options: |
| 42 | |
| 43 | {{{ |
| 44 | $ python myapp.py --help |
| 45 | Usage: myapp.py [options] |
| 46 | |
| 47 | Options: |
| 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 | }}} |