Search code examples
pythondjangocurlpostlamp

Sending a cURL POST request as a link


I have a LAMP Django API that sends out a text message to my customer which says Click [This Link] to do A and [Another Link] to do B.

I've been using POST requests to take in data to my API but that's been me polling directly from cURL in cmd. I want to create the request, then be able to send it out as a link to my client, then they click it and the post request is sent to my API.

Is this possible?

UPDATE: I have an ID number attached to each user. So this ID needs to persist from the API to the text and back to the API somehow.


Solution

  • You need to use something like the requests library. The only thing you need to do then is create a GET View, link your CLICK HERE so it resolves to that view, and then simply send the POST request from said View.

    from django.http import HttpResponse
    from django.views import View
    import requests
    
    class MyView(View):
    
        def get(self, request, *args, **kwargs):
            requests.post(your_url_here, data=your_body, headers=your_headers)
            return HttpResponse('POST request sent!')