我目前正在django项目中工作,我使用aiohttp在后端和前端之间进行通信。我想从前端发出请求时获取客户端的IP地址。在不同的文档中查看过,但似乎都没有指向如何使用aiohttp获取IP地址。有人帮忙!
from aiohttp import web
async def handler(request):
ws = web.WebSocketResponse()
await ws.prepare(request)
try:
async for msg in ws:
# handle incoming messages
# use ws.send_str() to send data back
...
finally:
task.cancel()