在命令行中,“pythonfile.pyshell”做什么?
我遇到了Django教程,其中讲师正在运行python manage.py shell 这将产生:在命令行中,“pythonfile.pyshell”做什么?,python,django,shell,Python,Django,Shell,我遇到了Django教程,其中讲师正在运行python manage.py shell 这将产生: (env) MBP:Project user$ python3 manage.py shell Python 3.7.6 (default, Jan 8 2020, 13:42:34) [Clang 4.0.1 (tags/RELEASE_401/final)] on darwin Type "help", "copyright", "credits" or "license" for mor
(env) MBP:Project user$ python3 manage.py shell
Python 3.7.6 (default, Jan 8 2020, 13:42:34)
[Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
两个问题:
shell在python manage.py shell中做什么?
上面提到的InteractiveConsole是什么意思?当我在没有shell的情况下运行python时,我看不到这一点。我在谷歌上搜索了InteractiveConsole,结果一无所获。
在这里如何管理.py?它是在运行还是在服务?
当您运行python manage.py shell时,您运行一个python或IPython解释器,但在解释器中加载所有Django项目配置,以便您可以对数据库或Django项目中可用的任何其他资源执行命令。
如果运行python manage.py,则只显示可与项目中的“manage.py”脚本一起使用的所有选项,如runserver或migrate
在shell中,您的项目不是作为http服务运行的,但是您可以执行诸如查询数据库或调用内部函数之类的操作。
三对三!非常感谢。如果我可以在这里问一下,你知道如何在一个模块中实现同样的功能吗?我想编写一些自动化代码,以从python模块更新Django中的表,即一个脚本,该脚本首先加载所有Django项目配置,然后我可以与数据库交互。在Django中,这被称为自定义命令,文档中有一个关于它的部分: