Ad

SEO And Django With Title And Description Tags

- 1 answer

I have a base.html for the base template for my files. Inside of it, I have tag where I define both title and description tags.

I also have my home page that is home.html that doesn't need a specific title or description and the general one for the whole website would do.

I also have detail.html which is the HTML that I use for every blog post where I am trying to improve SEO with using these tags

<meta name="description"
    content="{{ blog.formatted_summary|striptags }}">

<title>{{ blog.title|safe }}</title>

First off in HTML, it is not in the tag as it is already used. Secondly, I am basically defining both title and description twice and I can't think why that would be a good idea.

How do I insert the title and description into the base.html so if it is a blog post that I can specify to take the body or the summary as a description without defining the properties again?

Ad

Answer

A way to do this is to configure your base.html template to look for custom header data in the templates that leverage base.html

For example, you could put this in your base.html

<title>{% block title %}{% endblock %}</title>

Then, in your home.html file,

{% block title %}Homepage Title{% endblock %}

And in detail pages you can dynamically update titles with something like this:

{% block title %}Organization Name - {{ object.some_varyable_from_query }}{% endblock %}

Ad
source: stackoverflow.com
Ad