# 16、Django获取访问IP地址



```python
    #print(request.META)
    if 'HTTP_X_FORWARDED_FOR' in request.META:
        client_ip = request.META['HTTP_X_FORWARDED_FOR']
        client_ip = client_ip.split(",")[0] 
    else:
        client_ip = request.META['REMOTE_ADDR']
    print(client_ip)
```

\
