Start a Django server to provide the PyWebIO application as a web service. :param bool debug: Django debug mode. See `Django doc `_ for more detail. :param django_options: Additional settings to django server. For deta
(applications, port=8080, host='', cdn=True,
static_dir=None, remote_access=False,
allowed_origins=None, check_origin=None,
session_expire_seconds=None,
session_cleanup_interval=None,
debug=False, max_payload_size='200M', **django_options)
| 174 | |
| 175 | |
| 176 | def start_server(applications, port=8080, host='', cdn=True, |
| 177 | static_dir=None, remote_access=False, |
| 178 | allowed_origins=None, check_origin=None, |
| 179 | session_expire_seconds=None, |
| 180 | session_cleanup_interval=None, |
| 181 | debug=False, max_payload_size='200M', **django_options): |
| 182 | """Start a Django server to provide the PyWebIO application as a web service. |
| 183 | |
| 184 | :param bool debug: Django debug mode. |
| 185 | See `Django doc <https://docs.djangoproject.com/en/3.0/ref/settings/#debug>`_ for more detail. |
| 186 | :param django_options: Additional settings to django server. |
| 187 | For details, please refer: https://docs.djangoproject.com/en/3.0/ref/settings/ . |
| 188 | Among them, ``DEBUG``, ``ALLOWED_HOSTS``, ``ROOT_URLCONF``, ``SECRET_KEY`` are set by PyWebIO and cannot be specified in ``django_options``. |
| 189 | |
| 190 | The rest arguments of ``start_server()`` have the same meaning as for :func:`pywebio.platform.flask.start_server` |
| 191 | """ |
| 192 | if port == 0: |
| 193 | port = get_free_port() |
| 194 | |
| 195 | if not host: |
| 196 | host = '0.0.0.0' |
| 197 | |
| 198 | max_payload_size = parse_file_size(max_payload_size) |
| 199 | app = wsgi_app(applications, cdn=cdn, static_dir=static_dir, allowed_origins=allowed_origins, |
| 200 | check_origin=check_origin, session_expire_seconds=session_expire_seconds, |
| 201 | session_cleanup_interval=session_cleanup_interval, |
| 202 | debug=debug, max_payload_size=max_payload_size, **django_options) |
| 203 | |
| 204 | print_listen_address(host, port) |
| 205 | |
| 206 | if remote_access: |
| 207 | start_remote_access_service(local_port=port) |
| 208 | |
| 209 | use_tornado_wsgi = os.environ.get('PYWEBIO_DJANGO_WITH_TORNADO', True) |
| 210 | if use_tornado_wsgi: |
| 211 | import tornado.wsgi |
| 212 | container = tornado.wsgi.WSGIContainer(app) |
| 213 | http_server = tornado.httpserver.HTTPServer(container, max_buffer_size=max_payload_size) |
| 214 | http_server.listen(port, address=host) |
| 215 | tornado.ioloop.IOLoop.current().start() |
| 216 | else: |
| 217 | from django.core.management import call_command |
| 218 | has_coro_target = any(iscoroutinefunction(target) or isgeneratorfunction(target) for |
| 219 | target in make_applications(applications).values()) |
| 220 | if has_coro_target: |
| 221 | threading.Thread(target=run_event_loop, daemon=True).start() |
| 222 | |
| 223 | call_command('runserver', '%s:%d' % (host, port)) |
no test coverage detected
searching dependent graphs…