Debugging

Python Shell (Django shell)

From the installation directory, run:

cd hanji
./manage.py shell

Getting the objects (eg applet instances)

It is common to access one applet object as imported and instanciated by the server. It can be retrieved using:

from hanji.core import hanjicore
my_applet = hanjicore.applets['my_applet_id']

In Python, the self object as defined above is purely a convention, which allows to write in the shell in the same environment like in the code source:

self = hanjicore.applets['my_applet_id']

The applet’s webUI:

self.webUI

Applet module

In order to access an applet module definitions:

from hanji.applets.my_applet_id import *

Start Hanji from a development environment

To run a development environment (eg you have a package located in hanji_directory), use the --base-directory option. The --debug flag is also very useful for development, as it gives detailed logs, description of template errors, etc:

twistd --debug -n hanji --base-directory=<hanji_installation_dir> --debug
There are 2 --debug flags above:
twistd –debug

Allows the Python debugger to be used (works well with ipdb too). To break into the execution, use the usual:

import ipdb;ipdb.set_trace()

Note that you will have to press ‘c’ when the Twisted reactor starts.

hanji –debug
Use the uncompressed versions of Dojo (useful for tracing browser side errors), tell Django to log database access and get full debugging messages.

Also check the Developing with Eclipse page for running Hanji from Eclipse.

Eclipse

Eclipse with the PyDev extension provides great tools for debugging. See Developing with Eclipse.