Designing a GEO location API

You are designing a GEO Location API that provides geo location information based on IP addresses, using Django REST API. You are performing a GET request to the URL and reading the data in JSON format into the geodata variable, in the views.py file.

Which of the following options will best fit the missing line of code, XXX and YYY, to perform the action given in the above context?

from django.shortcuts import render

import requests

def home(request):

XXX

YYY

return render(request, ‘core/home.html’, {

‘ip’: geodata[‘ip’],

‘country’: geodata[‘country_name’]

})

Options
  1. XXX: response = requests.post(‘http://freegeoip.net/json/’)

YYY: geodata = response.json()

2.XXX: geodata = response.json()

YYY: response = requests.get(‘http://freegeoip.net/json/’)

3.XXX: geo = response.json()

YYY: response = requests.get(‘http://freegeoip.net/json/’)

4.XXX: response = requests.get(‘http://freegeoip.net/json/’)

YYY: geodata = response.json()

Related Posts

Close Bitnami banner
Bitnami