19

I would like to execute a command via Django's manage.py shell function solely from the command line

e.g.

manage.py shell -c "from myapp import models; print models.MyModel.some_calculation()"

the came way you might use the -c option with the normal Python interpreter

e.g.

python -c "print 'hello world'"

However, I don't see an equivalent -c option for manage.py shell. Is there a way to do this?

Cerin
  • 60,957
  • 96
  • 316
  • 522

2 Answers2

46

Pipe it ;)

echo "print('hello world')" | python manage.py shell
Jan Kyu Peblik
  • 1,435
  • 14
  • 20
kraiz
  • 2,178
  • 1
  • 22
  • 22
6

Not like that. But it is easy enough to write a standalone script for Django.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358