Request_data
get_ip
Function that obtains from the request the ip from which the request comes.
def get_ip(request):
ip = request.META["REMOTE_ADDR"]
if request.META.get("HTTP_X_FORWARDED_FOR"):
ip = request.META.get("HTTP_X_FORWARDED_FOR").split(",")[0]
return ip
get_device
Function that obtains from the request the device from which the request comes.
def get_device(request):
return "{0} {1} ({2})".format(
request.user_agent.browser.family,
request.user_agent.browser.version_string,
request.user_agent.os.family,
)