如何将导入预加载到Django的manage.py shell命令中? [英] How do I preload imports into Django's manage.py shell command?
问题描述
当我在Django项目上运行manage.py shell进行查看时,通常会在shell的开头运行一些常见的导入操作(例如,我始终希望导入模型文件。)我每次运行shell命令时都会自动运行这些代码吗?
When I run manage.py shell on my Django project to take a peek at something there are common imports that I always want to run at the start of the shell (e.g. I always want to import my model files.) How can I have these run automatically everytime I run the shell command?
第二个相关问题,当我按下向上箭头时,我得到的是 ^ A字符,而不是以前运行的字符在manage.py外壳程序(以及我的常规python外壳程序)中的命令,如何解决此问题,使其像在Linux / Unix命令行上一样加载上一个命令?
2nd related question, when I hit the up arrow I get the "^A" character instead of the previously run command in the manage.py shell (and in my regular python shell), how can I fix this so it loads the previous command like on the Linux/Unix command line?
推荐答案
对于第一个问题,请看 django-extensions 项目。它将在启动外壳时加载所有模型文件。该项目还有很多其他有用的技巧,因此绝对值得一试。
For the first question, look at the manage.py shell_plus
command provided by the django-extensions project. It will load all your model files on shell startup. The project has got a whole load of other useful tricks too, so it's definitely worth checking out.
对于第二个问题,我只能猜测您需要安装 readline
。
For the second question, I can only guess that you need to install readline
.
这篇关于如何将导入预加载到Django的manage.py shell命令中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!