tags:

views:

45

answers:

3

I'd like to browse active classes in Django. I think I'd learn a lot that way. So what's a good way to do that?

I could use IDLE if I knew how to start Django from within IDLE. But as I'm new to Python/Django, I'm not particularly wedded to IDLE. Other alternatives?

+1  A: 

I imagine what you mean by class browsing. If you are comfortable with the terminal you could try to inspect python/django objects via the shell and autocompletion.

$ ./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]: 
...

You may also like this enhanced version of the Django shell.

I also recommend the django documentation, e.g. if you like to learn about Request and Response objects:

How to enable tab-completion in the default python shell:

The MYYN
Thanks for the answer. I asked the question because I'm not thrilled with the quality of the documentation. It seems disjointed. For a simple example, I tried a google search on "django http response" expecting to be sent to a Django docs page that, among other things would tell me what I needed to IMPORT to access that class. I was sent to this page: http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest and no mention of the actual IMPORT statement needed to access.
jamida
+1  A: 

playing with the API

You can easily get a django project loaded in IDLE. All it needs is the project on sys.path and os.environ['DJANGO_SETTINGS_MODULE'] set to the settings package.

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

Should be all you need.

pycruft
+1  A: 

I suggest adding django-command-extensions addon application and then using:

  ./manage.py shell_plus

which loads all models from all applications at startup, saving a lot of time on typing "from myapp.models import MyModel"

And of course IPython - which is used by shell_plus if found - is superior to the default shell.

Tomasz Zielinski