http post, delete, get

My receipt printer is sending a string to django. How does django send/receive strings through http get/post/delete?
If it’s helpful, here’s the NodeJS equivalent: Mc print3 - Replit

Django itself does not initiate http transmissions. You would need to use something like the Python requests package for that.

1 Like

In the example nodeJs equivalent package, a http listener was created using express. Django can listen to http requests and return http responses the same way.

1 Like

Well, technically, Django does not listen to http requests.

The server that you use to run Django (gunicorn, uwsgi, Daphne, Werkzeug, etc) listens to http requests and converts them to wsgi (or asgi) requests, and calls Django. Django itself doesn’t do anything at the networking layer.

But yes, if the printer is initiating http requests, you would set up your server and your to handle those requests to direct them to an appropriate view.

1 Like

Thank you for sharing this. Every single time I make a get request, I always get it the source code of the webpage. Is it possible to get json from it? I’m not sure how this works. My receipt printer is suppose to send a post request to the url of my webpage every 5 seconds. So I just have run a http get on whatever they’re sending me and then find the json part of it?


Is very different than this:

If the printer is sending a post to your application, then you need to set up a url and view to handle it.
Is the JSON data you’re expecting part of that POST?

On the other hand, if you need to pull data from this device and it only responds with html, you may need to use something like BeautifulSoup to parse the html into something more useful.

(However, I would more expect that if the device is expecting you to retrieve JSON data, they would accept some parameter instructing it to return a JSON response.)

According to the docs, it says:

On each poll interval the client will send an http POST to the server. The POST is used to send live information to the server.

Client meaning the printer. Polling the server (POST)

I will try out BeautifulSoup. Thank you for your suggestion!

edited: I think the printer is sending a post to my app. I did set up a url and view, but I don’t know how to receive it. I tried using a get request and it gives me the html of the webpage. Post requests aren’t working. It’s giving me a 405 error

Then it’s up to you to write a view to handle that POST, and do whatever you want/need to do with the data being submitted by that POST, returning the appropriate response.

This is no different than any browser submitting a request. It’s handled exactly the same way.

My earlier point is that this is completely separate from you issuing a request to the printer to retrieve data.