Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing a Django Shell Command from the Command Line

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?

like image 477
Cerin Avatar asked Jan 25 '11 18:01

Cerin


2 Answers

Pipe it ;)

echo "print('hello world')" | python manage.py shell
like image 170
kraiz Avatar answered Sep 22 '22 03:09

kraiz


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

like image 29
Ignacio Vazquez-Abrams Avatar answered Sep 23 '22 03:09

Ignacio Vazquez-Abrams