Say I have the following view:
def show(request):
protect(request)
... some more code here...
return render_to_response
...
“protect” is another app view which I am importing like this: from watch.actions import protect
In protect, I make some checks and if a condition is met, I want to use render_to_response right from “protect” and prevent returning to show. If the condition is not met, I want to normally return to “show” and continue the code execution.
How may I do that?
Thanks.
If its only purpose is what you’ve described, you should consider writing
protectas a view decorator. This answer provides one example of how to do so.Based on view decorators that I have written, your
protectdecorator could look something like:Which would allow you to then use it like: