How To Debug Django Project With Eclipse And PyDev

When you develop python Django web project, you may find it is not easy to debug the source code even edit the source files. But with Eclipse PyDev, you can create and debug Django project easily and fix error quickly. This article will tell you how to use Eclipse PyDev to create and debug Django project files.

1. Create Django Project With PyDev Django Wizard.

  1. Open eclipse, click File —> New —> Others menu item. Then input Django in wizards input box to select PyDev Django Project as below and click Next button.create pydev django project dialog
  2. Input Django project name in the next dialog and select project contents directory then click Next button.
    input pydev django project name
  3. Select sqlite as the project default database. You can also select other database like mysql, oracle etc. Then click Finish button to complete the project creation.
    select sqlite as the pydev django project database

2. Create Django Application.

2.1 Create Django Application.

Now there is only the Django project directory in the eclipse PyDev. You should create a Django application in it.

  1. Open a terminal and go to above Django web project directory.
    $ cd /Users/zhaosong/Documents/WorkSpace/
  2. Run below command in terminal to create the Django application hello_world.
    $ python startapp hello_world
  3. Now refresh the Django project folder in eclipse, you can see hello_world folder has been created in it. Please note the hello_world / pages folder and hello_world / file is created by hand in later chapter.
    django web application directory files list

2.2 Edit DjangoProjectExample / File.

This file is Django web project configuration file, in this example you should change two sections in this file.

  1. Add hello_world application in the INSTALLED_APPS section as below.
    # Application definition
        # Add hello_world application.
  2. Set Django application html template page directory. Django application use html file as template page to render content to client, you should set the template html files saved directory in TEMPLATES section. The DIRS value is string list, you can set multiple directory as html template directory.
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            # If DIRS value is empty or '', it may throw TemplateDoesNotExist error.
            'DIRS': ['/Users/zhaosong/Documents/WorkSpace/'],
            'APP_DIRS': True,
            'OPTIONS': {
                'context_processors': [

2.3 Edit DjangoProjectExample / File.

This file is used to map client request url path to different Django application’s And the mappings between Django application request url and process view function is defined in the application’s file.

from django.contrib import admin
from django.urls import path,include
from django.conf.urls import url
import hello_world

urlpatterns = [
    # When the request url is http://localhost:8000/hello_world/ which application context path is hello_world, 
    # then Django server will use request url path and process view function mappings defined in hello_world/    
    url('^hello_world/', include(('hello_world.urls','hello_world'), namespace='hello_world')

2.4 Add hello_world / File.

from django.contrib import admin
from django.urls import path
from django.conf.urls import url
from . import views
import hello_world

urlpatterns = [
    # When request url is http://localhost:8000/hello_world/hello, it will invoke hello_world function defined in hello_world/
    # The first argument is the path relative to django application context path.
    path('hello', views.hello_world, name='helo_world'),

2.5 Edit hello_world / File.

This file contains python function which process client request by request url path. The request url path to function mapping is defined in hello_world/

from django.shortcuts import render
# This function is invoked to return html template page to client when the request url is http://localhost:8000/hello_world/hello
def hello_world(request):
    # The html file path relative to TEMPLATE DIRS directory defined in DjangoProjectExample / file..
    hello_world_file_path = 'hello_world/pages/index.html'
    # The context object will send back to client, it is a dictionary object contains a Message.
    context = {'Message' : 'Welcome to Django world.'}
    return render(request, hello_world_file_path, context)

2.6 Create Html Template Files.

  1. Create directory pages in hello_word folder.
  2. Create index.html file in pages directory. The html file content is very simple, it display the message sent back from server.
    <!DOCTYPE html>
    <meta charset="UTF-8">
    <title>Python Django Hello World</title>

3. Run / Debug Django Application.

  1. Right click the Django project, then click Run As / Debug As —> PyDev:Django menu item in the popup menu list. Then you can see the Django server start information in the console. If you set break point in your python source file, the execution will stop at the break point, then you can watch and inspect related variable values.
    right click django project click debug as pydev django project
  2. Below is the web page when browse url http://localhost:8000/hello_world/hello in web browser.
    django hello world example page
0 0 votes
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Oldest Most Voted
Inline Feedbacks
View all comments
Lucas Walkowicz
Lucas Walkowicz

It’s ok, but how you debug this, if you clone this project from git?

Can you explain the steps to debug cloned project?


Would love your thoughts, please comment.x