GalsenApi is an API that allows you to easily manipulate data on Senegal. A project inspired by the package. Galsenify
- Create a virtual environment:
python -m venv .venv
- Activate the virtual environment:
source .venv/bin/activate
- Install the dependencies:
pip install requirements.txt
- Run the migrations:
python manage.py makemigrations
python manage.py migrate
- Create a super user:
python manage.py createsuperuser
- Create a .env file in the Django project to store the secret key.
GET /api/regions/
GET /api/regions/1/
GET /api/departements
GET /api/departements/1/
GET api/villages
GET /api/villages/1
GET /api/pays/
To get all regions, use a GET request: https://galsenapi.pythonanywhere.com/api/regions/
Example Result
[
{
"id": 1,
"nom": "Dakar",
"code": "DK",
"population": 4042225,
"superficie": 547,
"departments": ["Dakar", "Pikine", "Guédiawaye", "Rufisque", "Keur Massar"]
},
{
"id": 2,
"nom": "Diourbel",
"code": "DB",
"population": 1980821,
"superficie": 4824,
"departments": ["Diourbel", "Bambey", "Mbacké"]
}
]
To get a single region, use a GET request: https://galsenapi.pythonanywhere.com/api/regions/1/
Example Result
{
"id": 1,
"nom": "Dakar",
"code": "DK",
"population": 4042225,
"superficie": 547,
"departments": ["Dakar", "Pikine", "Guédiawaye", "Rufisque", "Keur Massar"]
}
Created by Lassana SIBY
Thank you to Daouda BA for the data..
Views for regions and departments.
def regions_view(request):
query = request.GET.get('q')
url = 'https://galsenapi.pythonanywhere.com/api/regions/'
params = {'search': query} if query else {}
response = requests.get(url, params=params)
data = response.json()
regions = data
context = {'regions': regions, 'query': query}
return render(request, 'demo/regions.html', context)
def departments_view(request):
query = request.GET.get('q')
url = 'https://galsenapi.pythonanywhere.com/api/departements/'
params = {'search': query} if query else {}
response = requests.get(url, params=params)
data = response.json()
departments = data
context = {'departments': departments, 'query': query}
return render(request, 'demo/departements.html', context)
def villages_view(request):
query = request.GET.get('q')
url = 'https://galsenapi.pythonanywhere.com/api/villages/'
params = {'search': query} if query else {}
response = requests.get(url, params=params)
data = response.json()
villages = data
context = {'villages': villages, 'query': query}
return render(request, 'demo/village.html', context)