Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道在 python 中如何获取用户来自的主机?我如何提取它?
我试过这个:
host = self.request._environ['HTTP_HOST']
但它是空的......
你知道它应该是什么吗
谢谢。
self.request._environ['HTTP_HOST']告诉你你的主机名。
self.request._environ['HTTP_HOST']
您可以使用它self.request.remote_addr来获取远程 IP 地址。如果您需要其中的主机名,则需要进行反向 DNS 查找(可能会失败)。
self.request.remote_addr