Skip to content

Debugging a Django web App

jsargiot edited this page Apr 29, 2013 · 2 revisions

Ninja debugger plugin allows to debug a django app directly from Ninja-IDE! This page will show you how to do a basic debug of your app code.

Preparing the project for debugging

To be able to debug a django app, first we must have a Ninja-IDE project. Once the project is created, we need to set up the running parameters for the project.

I've created a simple app following the tutorial at: https://docs.djangoproject.com/en/1.5/intro/tutorial01/

The project looks like this:

Project

Before executing anything, we must tell the project how should execute. Right-click on the project, select Project Properties and click on the Project Execution tab, a window like the following should pop.

Project configuration

The first thing to configure is the main file. That is the file that Ninja-Ide will run as the project entry point. In our case, we'll set the manage.py file.

Next, the python interpreter, should point to your python executable.

The next important field is the "Params", where we add parameters that'll be passed to the main file. Since we are going to execute the manage.py as a server, we add the parameter "runserver".

Finally, if we have a virtualenv configured, set the path to the python executable inside that virtualenv.

We'll that should be enough configuration to run our project.

Starting the debug session

Before running the debug session, set the breakpoints you want to stop at. In the following image, I'm setting the breakpoint right before the view renders the text.

Breakpoints

Now, is ready to go.

Click on Addins -> Debug -> Debug main project.

That should show something like the following in the execution console:

Running: C:/jsargiot/TEMP/pyDebug/django-app/mysite/manage.py (Mon Apr 29 10:14:19 2013)

Validating models...

0 errors found
April 29, 2013 - 10:14:42
Django version 1.5.1, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

Now the server is running, if we hit the url: http://127.0.0.1:8000/polls (to hit the polls application) the browser will keep waiting and we should have our breakpoint activated:

Breakpoint active

You can see that we have a new thread, waiting at the breakpoint. From that point you can step through your code to see how it is working.

Once you have finished debugging, press the red "stop" button in the debug toolbar and the webserver will be terminated.

Hope this helps!