Django debugging with Emacs

前端 未结 6 904
小鲜肉
小鲜肉 2021-01-30 02:59

I found a lot of info about how to debug simple Python programs with Emacs. But what if I want to debug a Django application? I run the development server and I would like to so

6条回答
  •  青春惊慌失措
    2021-01-30 03:09

    This isn't emacs specific, but you can use the Python debugger by adding the following to a Django view function:

    import pdb; pdb.set_trace()

    Now when you run the development server and view the page, your browser will appear to hang or load very slowly - switch over to your console, and you have access to the full debugger. You can inspect AND modify state of your application via an interactive shell - check out the Python documentation for the debugger, or this link for some Python debugging examples


    If all you need is logging, add the following to your settings.py:

    logging.basicConfig(
        level = logging.DEBUG,
        format = '%(asctime)s %(levelname)s %(message)s',
        filename = '/tmp/mylog.log',
        filemode = 'w'
    )
    

    Now you can log messages to /tmp/mylog.log by adding the following to any view function:

    import logging
    logging.debug("Something happened")
    

提交回复
热议问题