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


#6

The default python2 runner doesn’t support django’s manage.py runserver unless you create your own custom runner (unless I’m missing something).

I can not for the life of me get debugging to work with my Django project in Cloud9.

Here’s what I currently have for my custom runner:

// This file overrides the built-in Python 2 runner
// For more information see http://docs.aws.amazon.com/console/cloud9/change-runner
{
“script”: [
//"$python manage.py migrate",
“if ; then “,
" echo ‘Debug’ && echo $project_path && echo $PWD && source venv/bin/activate && python -m ikpdb --ikpdb-port=15471 --ikpdb-working-directory=$project_path manage.py runserver $ip:$port --noreload”,
“else”,
" echo ‘run server’ && echo $project_path && echo $PWD && source venv/bin/activate && python manage.py runserver $ip:$port”,
“fi”,
“checkExitCode() {”,
" if https://forums.aws.amazon.com/ && ; 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”
}
}

From the Cloud9 terminal, if I just run:
source venv/bin/activate && python manage.py runserver $ip:$port

Then the manage.py server starts and I get pop-up with the publicly available link to my dev server. For example: .vfs.cloud9.us-east-1.amazonaws.com/
However, if I run this from the terminal:
source venv/bin/activate && python -m ikpdb --ikpdb-port=15471 --ikpdb-working-directory=$project_path/tribute manage.py runserver $ip:$port --noreload

I see the debugger start, but I don’t see any std out message from manage.py runserver

Has anyone else gotten Django debugging to work?