📜  获取用户 ip 地址 django - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:15.506000             🧑  作者: Mango

代码示例2
def visitor_ip_address(request):

    x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')

    if x_forwarded_for:
        ip = x_forwarded_for.split(',')[0]
    else:
        ip = request.META.get('REMOTE_ADDR')
    return ip