How to Create Progressive Web Apps (PWA) in Python?
Python is a fantastic programming language that you can use to create amazing things on the web.
Python frameworks such as Django and Flask power a large portion of the internet, and Python has emerged as one of the most popular backend programming languages for many reasons.
Python is also a great language for creating Progressive Web Apps (PWA). You can build installable web apps that can do a lot more than static websites can do. It only takes a few additional steps to your favorite web framework (Django or Flask)
Here’s how to convert your Python web app into a progressive web app.
Related: Use Pipe Operations in Python for More Readable and Faster Coding
Building progressive web apps using Django.
Django is a web framework that enables you to build web apps with Python quickly. Django includes everything you need to get started, including a web server, templating engine, and ORM.
To create a progressive web app with Django, you need to install the Django PWA package. This package provides all the tools you need to get started with progressive web apps. Django PWA also comes with a dozen of configuration options to customize.
Here are the steps to follow:
Step I: Install django-pwa
package from PyPI
pip install django-pwa
BashStep II: Add pwa
to installed_apps in Django app settings.
# <proj>/settings.py
INSTALLED_APPS = [
# other installed apps
'pwa',
]
PythonStep III: Set the static files directory
# <proj>/settings.py
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
# or any other location of your choice
]
PythonStep IV: Set the URL for progressive components in urls.py
# <proj>/urls.py
from django.urls import path, include
urlpatterns = [
# other path settings
path('', include('pwa.urls')),
]
PythonStep V: Load meta tags for the progressive web app in the base template
PWA_APP_NAME = 'The analytics club'
PWA_APP_DESCRIPTION = "The analytics club is a blog about data science, software development, and technology"
PWA_APP_THEME_COLOR = '#4669a2 '
PWA_APP_BACKGROUND_COLOR = '#fff'
PWA_APP_DISPLAY = 'standalone'
PWA_APP_SCOPE = '/'
PWA_APP_ORIENTATION = 'any'
PWA_APP_START_URL = '/'
PWA_APP_STATUS_BAR_COLOR = 'default'
PWA_APP_ICONS = [
{
'src': '/static/images/my_app_icon.png',
'sizes': '160x160'
}
]
PWA_APP_ICONS_APPLE = [
{
'src': '/static/images/my_apple_icon.png',
'sizes': '160x160'
}
]
PWA_APP_SPLASH_SCREEN = [
{
'src': '/static/images/icons/splash-640x1136.png',
'media': '(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2)'
}
]
PWA_APP_DIR = 'ltr'
PWA_APP_LANG = 'en-US'
PythonThanks for reading, friend! Say Hi to me on LinkedIn, Twitter, and Medium.
Not a Medium member yet? Please use this link to become a member because, at no extra cost for you, I earn a small commission for referring you.