How do I monitor views.py running

22 views
Skip to first unread message

Liu Duan

unread,
Feb 2, 2016, 1:00:32 PM2/2/16
to Django users

If I insert a line in views.py like:

      Print “Hello world.”

      Is there a way I can see the result?


In other words, how do I monitor views.py running?


      Thank you.

James Schneider

unread,
Feb 2, 2016, 1:43:46 PM2/2/16
to django...@googlegroups.com
The preferred method is to use logging: https://docs.djangoproject.com/en/1.9/topics/logging/

However, if you are running the dev server, print statements within any of your code will show on the console output where the dev server is running. 

I'd recommend spending a little time getting to know the logging system. It is much more flexible and allows you to increase/decrease verbosity when needed for troubleshooting, etc. It's also just as easy to use as a print statement after the initial setup (writing logging.debug() is pretty much as easy as print()). 

I also find that having those extra log lines works as pseudo documentation (hints are probably a better term) for what is/should be happening at that moment in the source. 

-James 

Liu Duan

unread,
Feb 2, 2016, 5:42:13 PM2/2/16
to Django users

        Thank you for your help.

        Here is what I figured out:

Anytime when views.py is changed it will run once, and the results will be shown on the server terminal window.

But each function runs only the function is called.

When a function is modified, the Class will run again.



在 2016年2月2日星期二 UTC-6下午12:43:46,James Schneider写道:
Reply all
Reply to author
Forward
0 new messages