Django获取客户的域名/主机名 [英] Django get client's domain name/host name
问题描述
获取用户的主机名/域名(如果可用)的最简单方法是什么?
还是有查找用户IP地址以查看其是否绑定到命名地址的功能? (即PHP中的gethostbyaddr())
What is the easiest way to obtain the user's host/domain name, if available? Or is there a function to lookup the IP address of the user to see if it is bound to a named address? (i.e. gethostbyaddr() in PHP)
HttpRequest.get_host()仅返回用户的IP地址。
HttpRequest.get_host() only returns the IP address of the user.
推荐答案
您不能依赖它,但是可以尝试 request.META ['REMOTE_HOST']
或 request.META ['HTTP_HOST'] $ c $来自
:请求
的 META
词典中的c>
You can't rely on it, but you can try the request.META['REMOTE_HOST']
or request.META['HTTP_HOST']
from the META
dictionary of the request
:
一个标准的Python字典,包含所有可用的HTTP标头。可用的标头取决于客户端和服务器,但以下是一些示例:
A standard Python dictionary containing all available HTTP headers. Available headers depend on the client and server, but here are some examples:
- REMOTE_HOST -- The hostname of the client.
- HTTP_HOST -- The HTTP Host header sent by the client.
这篇关于Django获取客户的域名/主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!