Debugging Django

debug
django
python

#1

I have had no luck searching for the answer on this so thought I would try here…

Does anybody know how to enable debugging on a Django project? It’s straightforward to debug a standard python app however the Django runner does not have a debug button.

I need to be able to set breakpoints anywhere within my Django app (for example in views.py) and have the program pause when I am opening the specific view in the browser so I can inspect variables etc.

Please help!

Thanks in advance.

Paul


#2

try using thr following runner, if it works well i’ll add it to the default configuration

// This file overrides the built-in Python 2 runner
// For more information see http://docs.c9.io:8080/#!/api/run-method-run
{
  "script": [
    "$python manage.py migrate",
    "if [ \"$debug\" == true ]; then ",
    "    python2 -m ikpdb --ikpdb-port=15471 --ikpdb-working-directory=$project_path manage.py runserver $ip:$port --noreload",
    "else",
    "  $python manage.py runserver $ip:$port",
    "fi",
    "checkExitCode() {",
    "    if [ $1 ] && [ \"$debug\" == true ]; then ",
    "        python -m ikpdb 2>&1 | grep -q 'No module' && echo '",
    "    To use python debugger install ikpdb by running: ",
    "        sudo apt-get update;",
    "        sudo apt-get install python-dev;",
    "        sudo pip install ikpdb;",
    "        '",
    "    fi",
    "   return $1",
    "}",
    "checkExitCode $?"
  ],
  "debugport": 15471,
  "$debugDefaultState": false,
  "debugger": "pythondebug",
  "selector": "^.*\\.(python|py)$",
  "python_version": "python2",

  "working_dir": "$project_path",
  "info": "Your code is running at \\033[01;34m$url\\033[00m.\n\\033[01;31m",
  "env": {
    "PYTHONPATH": "$python_path"
  }
}

#3

Thank you for the response.

Using the runner you supplied, the debugger gets started however when I set a breakpoint in a view function, the breakpoint is still not being triggered when I browse to the related url.

Regards

Paul


#4

i am not really familiar with django, maybe it starts a new python process.
could you give me an example of a project with which i can test.


#5

we have released a new version today which adds support for debugging to django runner for python 2