我不知道如何用一句话来解释我需要什么,但是让我们看看PHP中的示例。你知道吗
function sth() { exit(); }
echo 'you can see this';
sth();
echo 'this won't be shown';
?>
换句话说,在PHP中,我可以定义一个函数,在这个函数中,可以使用exit()立即停止脚本的执行
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"
您可以提前从视图返回:
要通过嵌套调用实现这一点,需要引发异常并从视图中处理它。但不要这样做,绝对没有必要这样做。如果您有不可访问的代码,那么应该完全删除它,而不是试图发明解决方法。你知道吗
相关问题 更多 >
编程相关推荐