从Django shell执行Python脚本 [英] Executing Python script from Django shell

查看:296
本文介绍了从Django shell执行Python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从Django shell执行一个Python脚本。我试过

  ./ manage.py shell<<< my_script.py 

但它没有起作用。

解决方案

<< 部分错误,请改用

  $ ./manage.py shell< myscript.py 

您还可以:

  $ ./manage.py shell 
...
>>> execfile('myscript.py')


I need to execute a Python script from the Django shell. I tried

./manage.py shell << my_script.py

But it didn't work. It was just kinda waiting for me to write something.

解决方案

The << part is wrong, use < instead:

$ ./manage.py shell < myscript.py

You could also do:

$ ./manage.py shell
...
>>> execfile('myscript.py')

这篇关于从Django shell执行Python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆