Skip to content

Commit

Permalink
Added an example using the init_app() method (Fixes #2110)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Jan 6, 2025
1 parent 932b9ab commit 78dda9b
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,32 @@ application::
if __name__ == '__main__':
socketio.run(app)

The ``init_app()`` style of initialization is also supported. To start the
web server simply execute your script. Note the way the web server is started.
The ``socketio.run()`` function encapsulates the start up of the web server and
replaces the ``app.run()`` standard Flask development server start up. When the
application is in debug mode the Werkzeug development server is still used and
configured properly inside ``socketio.run()``. In production mode the eventlet
web server is used if available, else the gevent web server is used. If
eventlet and gevent are not installed, the Werkzeug development web server is
used.
The ``init_app()`` style of initialization is also supported::

from flask import Flask, render_template
from flask_socketio import SocketIO

socketio = SocketIO()

def create_app():
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio.init_app(app)
return app

if __name__ == '__main__':
app = create_app()
socketio.run(app)


To start the web server simply execute your script. Note the way the web server
is started. The ``socketio.run()`` function encapsulates the start up of the
web server and replaces the ``app.run()`` standard Flask development server
start up. When the application is in debug mode the Werkzeug development server
is still used and configured properly inside ``socketio.run()``. In production
mode the eventlet web server is used if available, else the gevent web server
is used. If eventlet and gevent are not installed, the Werkzeug development web
server is used.

The ``flask run`` command introduced in Flask 0.11 can be used to start a
Flask-SocketIO development server based on Werkzeug, but this method of starting
Expand Down

0 comments on commit 78dda9b

Please sign in to comment.