How can I get Django to print the debug information to the console?

后端 未结 6 1833
故里飘歌
故里飘歌 2020-12-04 19:57

I\'m using urlib to hit my app not a browser so I can\'t see the debug screen when an error occurs. What\'s the best way to send the normal debug info to the console or a fi

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 20:18

    If you're running the development server locally, you can just use print.

    Also, you can use the logging module and redirect output to stdout. In settings.py put something like:

    import logging.config
    
    logging.config.fileConfig('/path/to/logging.conf')
    

    Then make a logging.conf file:

    [loggers]
    keys=root
    
    [handlers]
    keys=consoleHandler
    
    [formatters]
    keys=simpleFormatter
    
    [logger_root]
    level=DEBUG
    handlers=consoleHandler
    
    [handler_consoleHandler]
    class=StreamHandler
    level=DEBUG
    formatter=simpleFormatter
    args=(sys.stdout,)
    
    [formatter_simpleFormatter]
    format=format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
    

    Check out the python documentation for more details and more examples.

提交回复
热议问题