Browse Source

Add IPython support to flask shell

pull/1729/head
Jacopo Notarstefano 9 years ago
parent
commit
ea9a4bf134
  1. 11
      flask/cli.py

11
flask/cli.py

@ -427,8 +427,9 @@ def run_command(info, host, port, reload, debugger, eager_loading,
@click.command('shell', short_help='Runs a shell in the app context.')
@click.option('--ipython/--no-ipython', default=True)
@with_appcontext
def shell_command():
def shell_command(ipython):
"""Runs an interactive Python shell in the context of a given
Flask application. The application will populate the default
namespace of this shell according to it's configuration.
@ -448,6 +449,14 @@ def shell_command():
)
ctx = {}
if ipython:
try:
from IPython import embed
embed(banner1=banner, user_ns=app.make_shell_context())
return
except ImportError:
pass
# Support the regular Python interpreter startup script if someone
# is using it.
startup = os.environ.get('PYTHONSTARTUP')

Loading…
Cancel
Save