This website collects cookies to deliver better user experience
Page Title and Favicon in Django
Page Title and Favicon in Django
I will assume that you already have a Django web app set up, so we will dive right into how to add a page title and favicon to a Django website.
We only need two lines of code to do this.
Page Title
Let’s start with the page title. If you are using the local server, you should have something similar to this when running.
To change the page title, add the following line of code at the top your HTML template.
If you have any imports at the top, add the line after the imports.
I chose the name of my app (DEVBALT) for this example.
<title>DEVBALT</title><!-- baltlogs.com-->
After refreshing the page, you should see the page title.
There are two ways to do this. You can create a base template and have one page title for all pages of the website, or you can add a page title to each template depending on the page.
For example, I chose to display the name of my website (DEVBALT) for all pages on my website. However, you can choose to display CONTACT for the contact page, BLOG for the blog page, etc.
Favicon
Let’s tackle the favicon.
Django uses a variation of HTML templates which makes it easy to add the favicon. However, the line below won’t work.