Django Templates Guide

Django templates are a powerful feature of the Django web framework that allow you to create dynamic web pages. Templates are written in a language that is designed to be clear and easy to read, and it separates the presentation logic from the application logic.

Basic Structure

  • Template Tags: These are special syntax that tells Django to insert certain information into the page.
  • Filters: They allow you to modify the output of a variable.
  • Static Files: CSS, JavaScript, and images are included in templates using static files.

Example

{% extends "base.html" %}

{% block content %}
    <h1>Welcome to Django Templates</h1>
    <p>{{ user.name }} is currently logged in.</p>
{% endblock %}

Useful Links

Tips

  • Always use the {% block %} tag to define the main content of a page.
  • Remember to use the {% extends %} tag to inherit from a base template.

Images