I try to call a function which checks a rule and if the rule is not fulfilled I’d like to skip the rest of the view code and just return a HttpResponse Error.
I’d like to put all the escaping logic in a function because I need it at several points all over my project.
I tried to do something like this:
def myView(request):
checkFunction()
And:
def checkFunction():
#do stuff
return HttpResponse(status=403)
But it just don’t work (no wonder)…
Any ideas how to do this right?
Thanks
Ron
You can use a decorator for applying a logic to a view with possible redirect(if you can really put your logic outside the view).
and then in views.py: