📌 What is Data Warehousing? A data warehouse is a centralized system that stores and organizes large volumes of data …
Data WarehousingtoTurn Your Django Portfolio into a Progressive Web App (PWA) You can turn your Django-based portfolio into a Progressive Web App (PWA) so that users can install it on their …
Fotsing
March 3, 2025
You can turn your Django-based portfolio into a Progressive Web App (PWA) so that users can install it on their phones when they open it in a browser. Here’s how to do it:
Create a file named manifest.json inside your Django static/ directory.
{
"name": "AppName",
"short_name": "AppName",
"start_url": "/",
"display": "standalone",
"background_color": "#ffffff",
"theme_color": "#000000",
"icons": [
{
"src": "/static/icons/icon-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/static/icons/icon-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
]
}
Replace /static/icons/icon-192x192.png and /static/icons/icon-512x512.png with actual icons.
In your base.html (or the main template), add:
<link rel="manifest" href="{% static 'manifest.json' %}">
Create a service-worker.js file inside static/:
self.addEventListener("install", (event) => {
console.log("Service Worker installed.");
});
self.addEventListener("fetch", (event) => {
console.log("Fetching:", event.request.url);
});
Then, register it in your base template:
<script>
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("{% static 'service-worker.js' %}")
.then((reg) => console.log("Service Worker Registered", reg))
.catch((err) => console.log("Service Worker Failed", err));
}
</script>
Add this script in your template to trigger a beautiful install popup at the top:
<script>
let deferredPrompt;
window.addEventListener("beforeinstallprompt", (event) => {
event.preventDefault();
deferredPrompt = event;
let installPrompt = document.createElement("div");
installPrompt.innerHTML = `
<div class="install-prompt">
<span>Install Our App</span>
<button class="install-btn">Install</button>
</div>
`;
document.body.appendChild(installPrompt);
let style = document.createElement('style');
style.innerHTML = `
.install-prompt {
position: fixed;
top: 20px;
left: 50%;
transform: translateX(-50%);
background-color: #000;
color: #fff;
padding: 10px 20px;
border-radius: 5px;
display: flex;
justify-content: space-between;
align-items: center;
font-family: Arial, sans-serif;
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
z-index: 1000;
}
.install-btn {
background-color: #4CAF50;
border: none;
color: white;
padding: 8px 15px;
text-align: center;
font-size: 14px;
border-radius: 4px;
cursor: pointer;
font-weight: bold;
}
.install-btn:hover {
background-color: #45a049;
}
`;
document.head.appendChild(style);
const installBtn = installPrompt.querySelector(".install-btn");
installBtn.addEventListener("click", () => {
deferredPrompt.prompt();
deferredPrompt.userChoice.then((choiceResult) => {
if (choiceResult.outcome === "accepted") {
console.log("User installed the app");
}
installPrompt.remove();
});
});
});
</script>
✅ Ensure your site is served over HTTPS.
✅ Test by visiting your site on mobile and checking if the "Install" option appears.
Now, when users open your site on their phones, they'll see a stylish "Install App" popup at the top! 🚀
No comments yet. Be the first to comment!
📌 What is Data Warehousing? A data warehouse is a centralized system that stores and organizes large volumes of data …
Data Warehousing
In today’s fast-paced world, ⏳ time is our most valuable asset. Artificial Intelligence (AI) automation is transforming how we live …
Ai Agent🔐 Understanding How Django Handles Passwords Securely When building web applications, securing user passwords is crucial. Django, a powerful Python …
Django
Introduction In today's fast-paced digital world, users expect instant responses and seamless experiences. But as web applications grow more complex, …
Django
Lorsqu’une API Django passe en production, elle devient exposée à internet et peut être confrontée à plusieurs types d’attaques. Les …
Django
Django est un framework web open source écrit en Python, qui permet de créer rapidement des applications web robustes, sécurisées …
Django
Introduction Django est un framework web puissant pour Python, tandis que Tailwind CSS est un framework CSS moderne, utilitaire-first, …
Django
DEFO PHILIPPE STAGIER AU SEIN DE L’ENTREPRISE HOOYIA Rapport Hebdomadaire - Développement Django & Déploiement sur Render Introduction Ce …
Django 🌐 Django Channels : Le temps réel dans Django, enfin maîtrisé 🔍 Introduction Django est historiquement basé sur le …
DjangoAvec plaisir ! Voici un article professionnel et complet sur la multitenancy dans Django, idéal pour ceux qui veulent créer …
Django