def Contries(request):
for country in pycountry.countries:
list.append(country.name)
if list:
return JsonResponse(
{"code": status.HTTP_200_OK, "success": True, "response": list},
status=status.HTTP_200_OK)
else:
return JsonResponse(
{"code": status.HTTP_400_BAD_REQUEST, "success": False, "response":"list"},
status=status.HTTP_400_BAD_REQUEST)
Is there any possibility to get the list of cities and states of given country using python
This is an example of how you can use pycountry:
import pycountry
def cities_in_country(country):
list_ = []
for region in pycountry.subdivisions.get(country_code=country):
list_.append(region.name)
return list_
print(cities_in_country("FR"))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.