如果 true 停止处理并重定向到禁止,我将在 is_send_permitted_interceptor 排除此代码。但是,它没有,而是在函数中返回 HttpResponseForbidden 对象。
我如何真正让 HttpResponseForbidden() 在这种情况下运行。
@login_required
def process_all(request):
#If we had a POST then get the request post values.
if request.method == 'POST':
batches = Batch.objects.for_user_pending(request.user)
# Will redirect/cancel request if user does not meet requirements, funds, permissions etc
is_send_permitted_interceptor(request)
# stuff here if everything is ok
def is_send_permitted_interceptor(request):
# Check user has required credits in account to these batches.
balance = Account.objects.get(user=request.user).get_balance()
cost_of_sending = Batch.objects.batches_cost_pending(user=request.user)
if balance < cost_of_sending:
return HttpResponseForbidden()
else:
pass