Hi Django Developer,
I want to the user enter her/his phobne number and text message. So what I do:
In sms_page.html, the user enter the number and write the message. and then submit to go through the next page done.html that
message send successful
<!-- ========= sms_page.html =============== -->
<form action="/done" method="get">
<nav class="bg-light">
<div class="mb-3">
<label for="inputPassword" class="col-sm-2 col-form-label"><h5>Enter Phone Number</h5></label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputPhone" name="phone">
</div>
</nav>
<nav class="bg-light">
<div class="mb-3">
<label for="exampleFormControlTextarea1" class="form-label"><h5>Enter Your Text</h5></label>
<textarea class="form-control" id="exampleFormControlTextarea1" rows="3" name="text"></textarea>
</div>
</nav>
<center>
<button type="submit" class="btn btn-primary btn-lg"><h4>Send Message</h4></button>
</center>
</form>
After that I get the input from sms_page.html and sent to done.html by using views.py
def done_page(request):
phone = request.GET.get('phone')
text = request.GET.get('text')
return render(request, "en/done.html" , {'phn':phone , 'txt':text})
the result appear on done.html:
Now, I would like to using custom of api for sent the message:
http://www.4jawaly.net/api/sendsms.php?username=XXXXXX&password=XXXX&message=HelloTest&numbers=05XXXXX&sender=XXXX&unicode=e&Rmduplicated=0&return=Json
These function that can that set all parameter api and posted. But I’m not sure Is that correct?
def sendPostRequest( req_URL ,API_key , secret_API , text_message , phone_no , sender):
req_param = {
'apikey' : API_key,
'secretKey' :secret_API,
'message' :text_message ,
'phone' :phone_no,
'from': sender,
}
return requests.post(req_URL , req_param)
The last thing, I added to sent post the done.html:
def done_page(request):
phone = request.GET.get('phone')
text = request.GET.get('text')
t_phone = 'numbers='+ f'{phone}' + '&'
t_text = 'message=' + f'{text}' + '&'
# get resposnse
sendPostRequest(
URL ,'username=XXXXXX' , 'password=XXXXXXX' , t_text
, t_phone,'sender=Matager&unicode=e&Rmduplicated=0&return=Json')
return render(request, "en/done.html" , {'phn':phone , 'txt':text})
I have browsed through many tutorials on sms-gateways/carriers. But I am lost. Can you please guide me on how to sent SMS API in Django ?
