あなたの間違いは、myView
関数で を呼び出しますcheckFunction
が、 の戻り値を使用しないため、 の戻り値checkFunction
が checkFunction
return HttpResponse(status=403)
失われ、 内で返されませんmyView
。
次のようになります。
def myView(request):
result = checkFunction()
if result:
return result
#if no problem, keep running on...
def checkFunction():
#do stuff
if something_goes_wrong:
return HttpResponse(status=403)
# you do not need to return anything if no error occured...
したがって、何も問題がなければ何もcheckFunction
返さず、ブロックは実行されませんresult
。応答を返すと、ビューはその応答を返します (あなたの状況では)...None
if result:
HttpResponse(status=403)
更新: 次に、これを行うことができます....
def checkFunction(request):
#do stuff
if something_goes_wrong:
return HttpResponse(status=403)
elif some_other_issue:
return HttpResponse(....)
else: #no problems, everything is as expected...
return render_to_response(...) # or any kind of response you want
def myView(request):
return checkFunction(request)
このように、あなたのビューはあなたが返すものをcheckFunction
返します...
また、そこに応答を作成したいので、request
object を yourに渡す必要があるかもしれません。checkFunction
あなたはそれを必要とするかもしれません。