Reputation: 3802
I don't know how to explain in one sentence what I need, but let's look at the example in PHP.
function sth() { exit(); }
echo 'you can see this';
sth();
echo 'this won't be shown';
?>
In other words, in PHP I can define a function in which script can be instantly stopped executing with exit();
What about Django?
def sth():
# what to write here so that script will be stopped? pass
def some_view(request):
print "oh well, this will be seen either in the error log or the console."
sth()
print "this will not be printed"
Upvotes: 1
Views: 76
Reputation: 129914
You can return from the view early:
def some_view(request):
# ...
return direct_to_template(...)
# this code is unreachable
To achieve this with a nested call, you'd need to raise exception and handle it from the view. But don't do that, there is absolutely no need for such things. If you have unreachable code, then it should be just removed completely, instead of trying to invent workarounds.
Upvotes: 1