从函数django中终止端点
有没有办法从功能内部结束端点?我知道我可以使该函数返回真或错误,然后评估答案并返回,但是如果我可以做这样的事情,那将更加干净:
def custom_endpoint(self, request):
check_something(request)
return Response("ok")
check_something(请求)应检查变量,然后结束端点的执行如果一个变量不正确。
谢谢!!
Is there a way to end an endpoint from inside a function? I know I can make the function to return True or False, then evaluate that answer and return, but it would be a lot cleaner if I can do something like this:
def custom_endpoint(self, request):
check_something(request)
return Response("ok")
check_something(request) should check variables and then end the execution of the endpoint if one of the variables is not correct.
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的公用事业功能只能返回其呼叫者,即您的视图功能。您必须以某种方式使用实用程序函数的返回值来结束视图功能的执行。您的视图函数必须返回Web响应。
当然,您还可以使用错误处理机制,而不是在发生错误时使用返回值。
还将讨论在这里。
Your utility function can only return to its caller, i.e. your view function. You must somehow use the return value of your utility function to end the execution of your view function. Your view function must return a web response.
Of course, you can also use an error-handling mechanism instead of using return values in case of errors.
This is also discussed here.