'Making changes to django PWA
I had a all good working website in django and I was running that at http://127.0.0.1:8000/ with python manage.py runserver command. Then, I followed all steps at https://www.geeksforgeeks.org/make-pwa-of-a-django-project/ link, used their serviceworker.js as is and converted my website to a PWA. The issue is for the first time , the app loaded, I refreshed the page, the app loaded again. Since after, the app does not load but the code of serviceworker.js is shown on my screen every time I run server.
What is going wrong?
Here is the screenshot of the render:
Moreover, if I try to navigate to any of the app urls such as register, near_park etc, I see the 'Site can't be reached' message on screen and following error in console:
serviceworker.js:23 Uncaught (in promise) TypeError: Failed to fetch
at serviceworker.js:23
And please refer to the serviceworker.js file at the GeeksforGeeks link I provide above to view line 23.
Solution 1:[1]
you can use Django-simple-pwa just run
pip install django-simple-pwa
then add it to your installed apps
INSTALLED_APPS = [
...
'pwa',
]
then follow ducuments.
pypi: https://pypi.org/project/django-simple-pwa/
docs: https://django-simple-pwa.readthedocs.io/fa/latest/
documents are in Persian language but can translate to your local language with google translate I test it there is no translation problems
Solution 2:[2]
It wasn’t mentioned in all the tutorials I came across for setting up Django-pwa but it’s very essential for the operation of service in modern browser to switch the request protocol to HTTPS even for local development and testing . As aside this the service worker won’t work as expected .
Solution 3:[3]
For such things, I like to use the (not) in options
if fileFormat.lower() not in ["mp3", "mp4"]:
print("Error!")
else:
print("Correct!")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nima |
| Solution 2 | Brian Obot |
| Solution 3 | Emil105 |

