在批处理文件中运行带脚本的django shell

0 投票
1 回答
1311 浏览
提问于 2025-04-17 23:54

我想问一下,怎么在一个批处理文件里运行“python manage.py shell”,然后添加一段代码“from myapp.model import Contact c = Contact.objects.all().count() print c”。这样做可以吗?

1 个回答

2

试试下面的这个:

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

或者可以看看这个 在Python中如何从标准输入读取?

撰写回答