- Python-Django app to display Covid data
- Code from a tutorial by TopNotch Programmer - see 👏 Inspiration below
- Note: to open web links in a new window use: ctrl+click on link
- Displays Covid data from a Covid-19 API
- Python v3 programming language
- Django v3 server-side web framework
- Bootstrap v4
- Bootswatch v4 Bootstrap themes - Spacelab theme used
- Install Python
- Install pip
- Install Django by typing
pip install Django
- Run
django-admin startproject example_proj
to create a new project ref. docs - Open
example_proj
in VS Code - Run
python manage.py startapp new_module
to create Python module - Add code
- Run
pip freeze
to see list of modules installed. Ref. Docs - Run
python manage.py makemigrations
for changes to models etc. - Run
python manage.py migrate
to migrate the migration files. - For Admin panel: to add a superuser Run
python manage.py createsuperuser --username=joe --email=joe@example.com
Ref. Docs - Run
python manage.py runserver
to run server on port 8000 and open /admin console
- extract from
views.py
to get Covid data from API and prepare data required for html template
def home(request):
url = "https://covid-193.p.rapidapi.com/statistics"
querystring = {"country":"France"}
headers = {
'x-rapidapi-key': "a6f5f5daa9msh415e131fbb7e735p1994d1jsnb2bc491b075e",
'x-rapidapi-host': "covid-193.p.rapidapi.com"
}
response = requests.request("GET", url, headers=headers, params=querystring).json()
data = response['response']
d = data[0]
print(d)
context = {
'country': d['country'],
'all': d['cases']['total'],
'recovered': d['cases']['recovered'],
'deaths': d['deaths']['total'],
'new': d['cases']['new'],
'critical': d['cases']['critical'],
'date': d['day']
}
return render(request, 'index.html', context)
- Bootswatch v4 makes it very easy to change themes
- Status: Working
- To-do: Add commas to numbers. Move API code to services, add country pull-down selector.
- N/A
- Repo created by ABateman, email: gomezbateman@yahoo.com