Django ships with a few shortcuts like django.shortcuts.get_object_or_404 which come handy as they are frequently needed. I wrote a similar shortcut for the Django framework piston. This framework is used for the creation of RESTful APIs and is great as it makes it really easy to provide a RESTful API.
When using this framework you have something similar to views, called handlers. In this handlers you have methods like read which are implemented in a way quite similar to Django views. Unfortunately you can’t use get_object_or_404 as the Exception will be caught by piston and shown to the user. To overcome this issue I wrote the following function which tries to retrieve an entity and if it fails it will just return None (which will be rendered to null by piston).
That's me, Ben.
Hey, I am Ben Ripkens (bripkens)
and this is my blog.
I live in
Düsseldorf
(Germany)
and I am employed by the
codecentric AG as a Software Engineer.
Web application frontends are my main area of expertise, but you may also
find some other interesting articles on this blog.