Support `manage.py shell -c 'run_code_as_django()'`?

174 views
Skip to first unread message

Tim Graham

unread,
Nov 9, 2015, 3:28:54 PM11/9/15
to Django developers (Contributions to Django itself)
Similar to "python -c", there's been a request for:

python manage.py shell -c 'run_code_as_django()'

to avoid writing simple management commands. What do you think about this idea?

https://code.djangoproject.com/ticket/25680

Zach Borboa

unread,
Nov 10, 2015, 12:09:27 AM11/10/15
to Django developers (Contributions to Django itself)
I've used

cat script.py | python manage.py shell

Collin Anderson

unread,
Nov 11, 2015, 5:42:23 PM11/11/15
to Django developers (Contributions to Django itself)
I would use this feature. It would be nice for calling a simple function.

Though if we didn't add the feature it would be nice to document the text piping option.

The one downside of the piping is you get a little bit of garbage in the output, especially when iPython is installed.

Zach Borboa

unread,
Jan 12, 2016, 1:20:18 PM1/12/16
to Django developers (Contributions to Django itself)

Nice to see that this was implemented.


$ cat myscript.py
import django
print(django.__version__)

$ python manage.py shell --command="import myscript"
1.10.dev20160112100000



The --command option lets you pass a command as a string to execute it as Django, like so:

django-admin shell --command="import django; print(django.__version__)"

https://docs.djangoproject.com/en/dev/ref/django-admin/#django-admin-option---command

Reply all
Reply to author
Forward
0 new messages