Setting Up Icons and App Manifest for Your Django Web App

How to set required info for your Django app to comply for a Progressive Web App PWA requirements
November 4, 2024 by
Setting Up Icons and App Manifest for Your Django Web App
Hamed Mohammadi
| No comments yet

Visual appeal and ease of interaction play a crucial role in how users perceive and engage with a web application. This is particularly true if your Django web app aims to offer a Progressive Web App (PWA) experience, where the look and feel align closely with that of a native app. One way to accomplish this is by setting up custom icons and an app manifest. These elements help ensure that your app presents a unified visual identity, whether accessed on a smartphone, tablet, or desktop.

In this post, we’ll walk through the essential steps for adding icons and configuring an app manifest in your Django project, so your app is well-prepared to make a lasting impression.

Understanding the Basics

1. App Icons: Icons serve as visual cues for your app and are displayed on various screens, from the browser tab to mobile home screens. They also contribute to brand recognition, especially if users save your web app to their home screens.

2. App Manifest: The app manifest is a JSON file that provides important metadata about your web app, like its name, description, icons, and launch settings. It is key to enabling PWA capabilities, which allow your app to run in a standalone mode on users' devices and provide app-like features.

Setting Up App Icons

1. Prepare Your Icons

To ensure that your app displays correctly across all devices and browsers, create a set of icons in various sizes and formats. Here are some guidelines for creating app icons:

  • Sizes and Resolutions: Common sizes include 16x16, 32x32, 48x48, 64x64, 128x128, 192x192, and 512x512 pixels. Creating icons at these resolutions will help your app appear sharp on any device.
  • Formats: Use PNG for most icons as it supports transparency. SVG is another good option for high-quality scaling. However, keep a 16x16 or 32x32 favicon.ico for compatibility with older browsers.
  • Naming Convention: Use intuitive names for your icons, such as favicon.ico, apple-touch-icon.png, and android-chrome-512x512.png.

Many online tools, like RealFaviconGenerator or Favicon.io, allow you to generate these icons efficiently. They even create icons optimized for different platforms, which can save you time.

2. Add Icons to Your Django Project

Now, let’s incorporate these icons into your Django project:

  • Static Directory: In your project, create a directory for your icons under static/images.
  • Place Icons in the Directory: Add all generated icon files in this directory, ensuring you maintain consistent naming for easy reference in the app manifest.


Creating the App Manifest

1. Create the manifest.json File

Create a manifest.json file in your static directory (e.g., static/manifest.json). This file will contain information about your app that browsers use to present it as a PWA.

Here's a basic example of what to include. Save in with name site.webmanifest in static/image/ folder:

{
  "name": "My Website",
  "short_name": "Website",
  "description": "This is my website",
  "start_url": "/",
  "icons": [
    {
      "src": "/static/images/web-app-manifest-144x144.png",
      "sizes": "144x144",
      "type": "image/png",
      "purpose": "any"
    },
    {
      "src": "/static//images/web-app-manifest-192x192.png",
      "sizes": "192x192",
      "type": "image/png",
      "purpose": "maskable"
    },
    {
      "src": "/static/images/web-app-manifest-512x512.png",
      "sizes": "512x512",
      "type": "image/png",
      "purpose": "maskable"
    }
  ],
  "screenshots": [
    {
      "src": "/static/images/screenshot1.png",
      "sizes": "1920x1080",
      "type": "image/png"
    },
    {
      "src": "/static/images/screenshot2.png",
      "sizes": "1080x1920",
      "type": "image/png",
      "form_factor": "narrow"
    },
    {
      "src": "/static/images/screenshot1.png",
      "sizes": "1920x1080",
      "type": "image/png",
      "form_factor": "wide"
    }
  ],
  "theme_color": "#ffffff",
  "background_color": "#ffffff",
  "display": "standalone"
}


Add links to base template

<!-- favicon -->
    <link rel="icon" type="image/png" href="{% static 'images/favicon-96x96.png' %}" sizes="96x96" />
    <link rel="icon" type="image/svg+xml" href="{% static 'images/favicon.svg' %}" />
    <link rel="shortcut icon" href="{% static 'images/favicon.ico' %}" />
    <link rel="apple-touch-icon" sizes="180x180" href="{% static 'images/apple-touch-icon.png' %}" />
    <link rel="icon" type="image/png" href="{% static 'images/web-app-manifest-192x192.png' %}" sizes="192x192" />
    <link rel="icon" type="image/png" href="{% static 'images/web-app-manifest-512x512.png' %}" sizes="512x512" />
    <link rel="icon" type="image/png" href="{% static 'images/web-app-manifest-144x144.png' %}" sizes="144x144" />
    <link rel="manifest" href="{% static 'images/site.webmanifest' %}" />
    <meta name="apple-mobile-web-app-title" content="My Website" />
    <!-- end icons -->
Note we have added meta name for Apple mobile web title, too.

A nice site for doing this when you have your logo file ready is:

https://realfavicongenerator.net/

After generating all required icons for you, it also allows you to test your setup. 

You can also use Google Chrome or Firefox Developers Tool to test your set up. After opening your website, open Developers tools and navigate to Application tap. 

If everything is Okay, users can easily install your website as a native App on Desktop, iOS, and Android.

Conclusion

By following these steps to set up icons and an app manifest, you’re well on your way to delivering a more polished, native-like experience for users of your Django web app. With PWA capabilities, users can add your app to their home screen, access it offline, and enjoy a cohesive design across devices. This setup not only improves user experience but also increases engagement, helping your app stand out in a competitive digital landscape.


Setting Up Icons and App Manifest for Your Django Web App
Hamed Mohammadi November 4, 2024
Share this post
Tags
Archive

Please visit our blog at:

https://zehabsd.com/blog

A platform for Flash Stories:

https://readflashy.com

A platform for Persian Literature Lovers:

https://sarayesokhan.com

Sign in to leave a comment