new
parent
e29ab2c80c
commit
0997f656c1
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,3 +1,18 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
# Create your views here.
|
||||||
|
|
||||||
|
def get_client_ip(request):
|
||||||
|
client_ip = request.META.get('REMOTE_ADDR', '')
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = requests.get(f'http://ipinfo.io/{client_ip}/json')
|
||||||
|
data = response.json()
|
||||||
|
country = data.get('country', 'Unknown')
|
||||||
|
except Exception as e:
|
||||||
|
country = "Unknown"
|
||||||
|
|
||||||
|
return JsonResponse({'ip': client_ip, 'country': country})
|
Binary file not shown.
Loading…
Reference in New Issue