0

I would like to use pdb to debug a view in Django but so far i've been unsuccessful, getting a BdbQuit error:

The view i've tried this on is a simple get request:

def get_file_names(request):
    pdb.set_trace()
    my_files = Files.objects.filter(user_id=request.user))
    name_list += list(map(lambda x: (x.id, x.name, x.description),
                          my_files))

    return JsonResponse({'rows': name_list})

A couple notes:

  • I prefer not to use Django pdb since this forces me to modify the client's request parameters.

  • I also do not want to call my code from pdb (since this code is being called from the client).

  • Django Version 1.10.6
  • The app is running inside a docker container

Does anyone have a solution which works? Im finding that debugging complex web requests in python can be very tedious and it would be really amazing if pdb worked.

Note this is not a subprocess, just a simple get request (eventually i would like it to work on a more complex request but i've posted a simple example since this already fails).

Any suggestions? Suggestions here dont seem to work.

DannyMoshe
  • 6,023
  • 4
  • 31
  • 53

1 Answers1

0

In order to run pdb inside a Django app running inside a container, you must run with the -it flags.

docker run -it .... djangoimage

If you're running detached (-d), you can attach to your container docker attach $IDCONTAINER.

If you're running with docker-compose:

services:
  django:
    # ...
    stdin_open: true
    tty: true

And then use the docker attach to attach to the Django container when you run the pdb.

Douglas Miranda
  • 331
  • 3
  • 9