Saturday, September 1, 2012

Re: What does this code do? Also, testing decorator via terminal?

Hi Kurtis! Many thanks for your reply, I really appreciate the help! :)

On Fri, Aug 31, 2012 at 11:38 PM, Kurtis Mullins
<kurtis.mullins@gmail.com> wrote:
> All that is doing is checking to see if the object named "objects" is an
> HttpResponse object.

Ah, ok! I think you've kicked me in the right direction here.

> that the objects.status_code *should* work, although I'm not sure if it
> returns a number or a string. I'm not sure why this isn't working for you,
> though.

I think it's not working for me because, in my view, I'm not returning:

return HTTPResponse(json.dumps(d), content_type='application/json')

... instead, I'm returning:

return {'this will be': 'JSON'}

Based on your reply, I think I now understand why the original author is using:

if isinstance(objects, HttpResponse):

... meaning, "don't do anything with `objects` if the view is already
passing an HTTPResponse". Essentially, that logic is just trying to
make sure that the view passes the right type of object to the
decorator... Correct? If so, then that's lesson learned for me: Never
try to combine two decorators before fully understanding how the code
works! :D

I thought I was being cool by trying to combine the two... But now I'd
rather spend my time learning how to convert this decorator so that it
works on CBVs.

Thanks again for the help Kurtis, I really appreciate it!!!!

Cheers,
Micky

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment