Django shell
$ tree
.
├── core
│ └── models.py
│ ...
└── manage.py
...
1 directory, 2 files
打开你本地的终端(不是在Python解析器里面) 然后输入这个命令:
$ python manage.py shell
Python 2.7.10 (default, Feb 22 2019, 21:55:15)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>>
>>> from .core import models
>>> models.Channel.objects.all()
<QuerySet [<Channel: Channel object>, <Channel: Channel object>, <Channel: Channel object>, <Channel: Channel object>, <Channel: Channel object>, <Channel: Channel object>, <Channel: Channel object>, <Channel: Channel object>, <Channel: Channel object>, <Channel: Channel object>, <Channel: Channel object>, <Channel: Channel object>, <Channel: Channel object>, <Channel: Channel object>, <Channel: Channel object>]>
类似的,这里也是通过 from xxx import xxx
语句引用一个模块,所以可以直接调用 models
模块的方法,即通过 [方法名]()
,而方法名前不再需要声明该方法所属的模块。
Reference
FEATURED TAGS
algorithm
algorithmproblem
architecturalpattern
architecture
aws
c#
cachesystem
codis
compile
concurrentcontrol
database
dataformat
datastructure
debug
design
designpattern
distributedsystem
django
docker
domain
engineering
freebsd
git
golang
grafana
hackintosh
hadoop
hardware
hexo
http
hugo
ios
iot
java
javaee
javascript
kafka
kubernetes
linux
linuxcommand
linuxio
lock
macos
markdown
microservices
mysql
nas
network
networkprogramming
nginx
node.js
npm
oop
openwrt
operatingsystem
padavan
performance
programming
prometheus
protobuf
python
redis
router
security
shell
software testing
spring
sql
systemdesign
truenas
ubuntu
vmware
vpn
windows
wmware
wordpress
xml
zookeeper