【Python】Django - Django Shell

Posted by 西维蜀黍 on 2020-08-09, Last Modified on 2021-09-21

shell

$ python manage.py shell
Python 2.7.12 (default, Nov 12 2018, 14:36:49)
Type "copyright", "credits" or "license" for more information.

IPython 2.4.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]:

执行长串代码

$ python manage.py shell 
In [1]: %autoindent
Automatic indentation is: OFF
In [2]: %cpaste
/# 输入代码
--

dbshell

python manage.py dbshell -h
Usage: manage.py dbshell [options]

Runs the command-line client for specified database, or the default database if none is provided.

Options:
  -v VERBOSITY, --verbosity=VERBOSITY
                        Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very
                        verbose output
  --settings=SETTINGS   The Python path to a settings module, e.g. "myproject.settings.main". If this
                        isn't provided, the DJANGO_SETTINGS_MODULE environment variable will be used.
  --pythonpath=PYTHONPATH
                        A directory to add to the Python path, e.g. "/home/djangoprojects/myproject".
  --traceback           Raise on exception
  --database=DATABASE   Nominates a database onto which to open a shell.  Defaults to the "default"
                        database.
  --version             show program's version number and exit
  -h, --help            show this help message and exit
$ python manage.py dbshell [--database=DATABASE]

Reference