0

I am new in the web dev. And have some questions. I hope someone can help me.

when I send a get request from an external device to my django server I do it like that:

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)             

s.connect(("127.0.0.1" , 8000))    
s.sendall(b'GET / \n\n')
s.recv(100)
s.close

How can I see an address of a machine which sends a GET request to my web server (everything in the local network)? How can I send some data back to the same machine after receiving the GET request?

I also would like to be able to send a get request with some message what the device needs so the view in django can proccess it. How can I from the GET request with a additional message?

I use django, server and external devices are connected to the same network

thank you in advance,

user
  • 95
  • 1
  • 9

1 Answers1

1
  1. Check the following stack overflow link to get the IP address: How do I get user IP address in django?

  2. The web server(The Django development server/ Nginx/ Apache) will handle the connections to your web application. They will help to send the response back to the same client(same IP) who send the request. So you need to write a view function which will return render/HttpResponse/Some other kind of response.

eg:

def index(request):
    some_dict = {'ip': '192.168.1.1', }
    return render(request, 'polls/index.html', some_dict)
    #return HttpResponse()
Jisson
  • 3,566
  • 8
  • 38
  • 71
  • great thank you :) It works. And for a different GET request for a specific data I can create a separate views in Django. – user May 24 '20 at 16:20