[英]Waiting for another request in Django view
標題幾乎是自我解釋的,我需要我的一個視圖等待另一個視圖被調用或超時。 它看起來像這樣:
class WaitingView(APIView):
def post(self, request):
...do_things
called = wait_for_DeblockingView_or_timeout()
if called:
return Response(200)
return Response(408)
class DeblockingView(APIView):
def post(self, request):
...do_things
send_some_signal_to_unlock()
return Response(200)
我已經嘗試使用threading
模塊的Event
object,利用它的wait()
和set()
方法,但要么我做錯了要么它不是 go 對於這個用例的方法。 更多關於這里的嘗試。
您可以使用session
變量在視圖之間共享數據:
class WaitingView(APIView):
def post(self, request):
...do_things
called = request.session.get('deblocking_call')
if called is True:
del request.session['deblocking_call']
return Response(200)
return Response(408)
class DeblockingView(APIView):
def post(self, request):
...do_things
request.session['deblocking_call'] = True
return Response(200) ## I would use 'return redirect("waiting_view")'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.