在Django上课

时间:2010-05-29 22:44:51

标签: python django

我想在Django中浏览活动类。我想我会通过这种方式学到很多东西。那么这样做有什么好办法呢?

如果我知道如何从IDLE中启动Django,我可以使用IDLE。但由于我是Python / Django的新手,我并不是特别喜欢IDLE。其他替代方案?

3 个答案:

答案 0 :(得分:1)

我想象你通过课堂浏览的意思。如果您对终端感到满意,可以尝试通过shell和自动完成检查python / django对象。

$ ./manage shell
Python 2.6.4 (r264:75706, Feb  6 2010, 01:49:44) 
Type "copyright", "credits" or "license" for more information.

IPython 0.10 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object'. ?object also works, ?? prints more.

In [1]: from your.app.models import *
In [2]: 
...

您可能也喜欢this enhanced version of the Django shell

我还推荐django文档,例如:如果您想了解RequestResponse个对象:

如何在默认的python shell中启用tab-completion:

答案 1 :(得分:1)

playing with the API

您可以轻松地在IDLE中加载django项目。它所需要的只是sys.path上的项目和设置为设置包的os.environ['DJANGO_SETTINGS_MODULE']

E.g。

import sys
import os
sys.path.append("/path/to/parent") # under which myproject is hosted
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
import myproject.myapp.models # or whatever

应该是你所需要的一切。

答案 2 :(得分:1)

我建议添加django-command-extensions插件应用,然后使用:

  ./manage.py shell_plus

在启动时从所有应用程序加载所有模型,节省大量时间“从myapp.models导入MyModel”

当然IPython - shell_plus如果找到的话 - 优于默认的shell。