项目作者: AndrewJBateman
项目描述 :
:clipboard: Displays covid API data using Bootstrap and Bootswatch theme.
高级语言: Python
项目地址: git://github.com/AndrewJBateman/python-django-covid.git
Python Django Site
- 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




Table of contents
General info
Screenshots

Technologies
Setup
- 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
Code Examples
- 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)
Features
Status & To-do list
- Status: Working
- To-do: Add commas to numbers. Move API code to services, add country pull-down selector.
Inspiration
License