Answer the question
In order to leave comments, you need to log in
How to properly handle a callback in django?
There is a site on which it is necessary to process the callback. Since I have never done this, I ask you to comment on the correctness of my thoughts.
1. Callback is a normal external request. That is, the nature of this request is not important to me - it can be initiated by both the client's browser and any third-party service
2. Is the callback just a GET request or maybe POST ?
3. for processing, I create a separate address in url.py on which a regular view hangs with an incoming request. Further, I parse this request into parts depending on the structure of the data given to me?
4. If question 3 is yes, then what to do if some attacker starts sending garbage to this address?
5. I need to return "ok" as an answer. Here I did not understand at all. Where exactly to return this ok? Just write return HttpResponse('ok') at the end of the view?
I think it makes no sense to create a new topic, I will continue here.
Here is what I wrote for handling the callback:
class CallBackPage(View):
def get(self, request):
with open(BASE_DIR / 'logs/callback.log', 'a', encoding='utf-8') as f:
f.write('callback log get' + '\n')
f.write(str(request.GET) + '\n')
return HttpResponse('ok')
def post(self, request):
with open(BASE_DIR / 'logs/callback.log', 'a', encoding='utf-8') as f:
f.write('callback log post' + '\n')
f.write(str(request.POST) + '\n')
return HttpResponse('ok')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question