diff --git a/django/core/management/commands/shell.py b/django/core/management/commands/shell.py index 3baf75c104..96169020e5 100644 --- a/django/core/management/commands/shell.py +++ b/django/core/management/commands/shell.py @@ -1,3 +1,4 @@ +import os from django.core.management.base import NoArgsCommand from optparse import make_option @@ -43,4 +44,16 @@ class Command(NoArgsCommand): import rlcompleter readline.set_completer(rlcompleter.Completer(imported_objects).complete) readline.parse_and_bind("tab:complete") + + # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system + # conventions and get $PYTHONSTARTUP first then import user. + if not use_plain: + pythonrc = os.environ.get("PYTHONSTARTUP") + if pythonrc and os.path.isfile(pythonrc): + try: + execfile(pythonrc) + except NameError: + pass + # This will import .pythonrc.py as a side-effect + import user code.interact(local=imported_objects)