Django Gunicorn Debug

后端 未结 5 471
陌清茗
陌清茗 2021-01-11 23:52

Initially I had a Django app with the included testing server. To debug this setup, I can just add a import pdb; pdb.set_trace() anywhere in the code and have a

5条回答
  •  情书的邮戳
    2021-01-12 00:36

    If you are able to launch gunicorn pointing at an application instance that is an instance of the DebuggedApplication class from the werkzeug library, you will be able to set break points using the werkzeug debugger with import ipdb; ipdb.set_trace() right in your browser.

    import django.core.handlers.wsgi
    from werkzeug.debug import DebuggedApplication
    
    application = django.core.handlers.wsgi.WSGIHandler()
    application = DebuggedApplication(application, evalex=True)
    

    Make sure you install werkzeug library and ipdb of course. (pip install werkzeug and pip install ipdb)

提交回复
热议问题