-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews.py
More file actions
29 lines (26 loc) · 958 Bytes
/
Copy pathviews.py
File metadata and controls
29 lines (26 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from django.contrib.gis.geoip import GeoIP
def home(request):
address = request.META['HTTP_X_FORWARDED_FOR']
ip = address.split(',')[-1].strip()
g = GeoIP()
country = g.country(ip)
for key,value in country.items():
if key == "country_code":
country_code = value
continent = coun_code(country_code)
if continent == 'america':
if request.user_agent.is_touch_capable:
return render(request,'mobileUS.html')
else:
return render(request,'homeUS.html')
else:
if request.user_agent.is_touch_capable:
return render(request,'mobilehome.html')
else:
return render(request,'home.html')
def coun_code(code):
world_dict=[
('continent',['countries codes'...]
for continent,country in world_dict:
if code in country:
return continent