Django реализация оператора if-else
Я хочу реализовать платежную систему на django, используя платежную платформу mpesa. Я также хочу печатать "hello world" на консоли каждый раз, когда страница загружается или когда request.POST.get('action') == 'post' не срабатывает при обращении к функции. Мой код приведен ниже.
def pay_online(request):
response_data = {}
current_user = request.user
queryset = Individual.objects.filter(user = request.user.id)
if queryset.exists():
queryset = Individual.objects.get(user = request.user.id)
else:
queryset = Business.objects.get(user = request.user.id)
if request.POST.get('action') == 'post':
print("hello world 1")
MpesaNo = request.POST.get('mpesaNumber')
response_data['message'] = "Check your phone for ussd prompt to complete the payment."
access_token = MpesaAccessToken.validated_mpesa_access_token
api_url = "https://sandbox.safaricom.co.ke/mpesa/stkpush/v1/processrequest"
headers = {"Authorization": "Bearer %s" % access_token}
request = {
"BusinessShortCode": LipanaPpassword.Business_short_code,
"Password": LipanaPpassword.decode_password,
"Timestamp": LipanaPpassword.lipa_time,
"TransactionType": "CustomerBuyGoodsOnline",
"Amount": queryset.ccTotal,
"PartyA": Number,
"PartyB": LipanaPpassword.Business_short_code,
"PhoneNumber": Number,
"CallBackURL": "https://sandbox.com",
"AccountReference": "Trial",
"TransactionDesc": "Trial payments"
}
response = requests.post(api_url, json=request, headers=headers)
return JsonResponse(response_data)
else:
print("hello world")
context = {'queryset':queryset}
template = 'payments_page.html'
return render(request, template, context)
Мой главный вопрос заключается в том, почему не отображается "hello world" на консоли, когда request.POST.get('action') == 'post' не срабатывает.