About Semantic HTML
When creating includable Django template snippets, use semantic HTML for better accessibility, machine readability, maintainability, and future proof. For example:
{# posts/includes/post_list_item.html #}
{% load i18n tz humanize %}
<article>
<header>
<h2>
<a href="{{ post.get_absolute_url }}">{{ post.title }}</a>
</h2>
<p class="post-meta">
{% blocktranslate trimmed with author_name=post.author.get_full_name author_url=post.author.get_absolute_url %}
By <a href="{{ author_url }}" rel="author">{{ author_name }}</a>
{% endblocktranslate %}
<time datetime="{{ post.published_at|utc|date:'c' }}"
title="{% blocktranslate with timestamp=post.published_at|utc|date:'DATETIME_FORMAT' %}{{ timestamp }} UTC{% endblocktranslate %}">
{{ post.published_at|naturaltime }}
</time>
</p>
</header>
{{ post.excerpt|linebreaks }}
<footer>
{% if post.tags.all %}
<ul class="tags">
{% for tag in post.tags.all %}
<li><a href="{{ tag.get_absolute_url }}">{{ tag.name }}</a></li>
{% endfor %}
</ul>
{% endif %}
<a href="{{ post.get_absolute_url }}">{% translate "Read more" %}</a>
</footer>
</article>
Usage:
<ul class="post-list">
{% for post in posts %}
<li>{% include "posts/includes/post_list_item.html" %}</li>
{% endfor %}
</ul>
Tips and Tricks Search Engine Optimization (SEO) Templates Django 6.x Django 5.2 Django 4.2
Django/Python Consulting
If you have a specific Django challenge or integration you'd like to solve, I'd be happy to help. Book a free 30-minute call to discuss your project, see if we're a good fit, and explore the best approach for your needs. After the call, you'll receive a tailored cost estimate based on what we discuss.
Also by me
Django Messaging
For Django-based social platforms.
Django Paddle Subscriptions
For Django-based SaaS projects.
Django GDPR Cookie Consent
For Django websites that use cookies.