Search code examples
pythondjangodjango-shell

Run a django shell in batch file with script


I wanna ask how to make a "python manage.py shell" and add a "from myapp.model import Contact c = Contact.objects.all().count() print c". Is this possible in a batch file?


Solution

  • Try something like:

    echo "from myapp.model import Contact; c = Contact.objects.all().count(); print c" | python manage.py shell
    

    Or this How do you read from stdin in Python?