Laravel's dd() equivalent in django

后端 未结 3 981
青春惊慌失措
青春惊慌失措 2021-01-01 17:11

I am new in Django and having a hard time figuring out how to print what an object have inside. I mean type and value of the variable with its members inside. Just like Lara

3条回答
  •  醉梦人生
    2021-01-01 17:47

    Raise an exception. Assuming you've got debug on you'll see the exception message. It's crude but it's helped me in the past.

    Just:

     raise Exception("I want to know the value of this: " + myvariable_as_a_string)
    

    Other answers & commenters ignored the crucial "and die" part of the dd() function, which prevents things like subsequent redirects.

提交回复
热议问题