Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


How to use comments in Django template tags

Njoku Ifeanyi Gerald

A Django template is a text document like HTML added some jinja syntax.

The syntax of the Django template language involves four constructs: {{ }} or {% %}.

In this shot, we are gonna be looking at Django comments, or how to use Django comment tags in an HTML file. A comment is mostly used by the developer to remember a line or to state what a particular line of code does.

Comments do not display on the home screen and are merely lines that can only be seen when looking at the source code, not from the browser but by downloading/cloning the main source code example from GitHub.

An example of comments is shown below:

{% comment "things to remember" %}
    remember to input data
{% endcomment %}

Let’s start with installation.

Step 1

pip install pipenv
pipenv shell
pipenv install django

Step 2

django-admin startproject DjangoCommentTag ./
python startapp codebase

Step 3

python migrate
python runserver

Step 4

Go to and add the following.

# Application definition



Step 5

In, add the following:

from django.shortcuts import  render

def home(request):
  life = 'it is just my passion to code out the world'

  context = {
      'life': life
  return render(request, 'app/home.html', context)

Step 6

In the codebase app, create a folder and name it templates.

Inside the templates folder, create another folder and name it app. Then, inside the app folder, create an home.html file.


<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <h1> History</h1>    
    {% comment "things to remember" %}
        <p>remember to input data here</p>
    {% endcomment %}

Step 7

In the file in the DjangoCommentTag folder, add the following.

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    # including the codebase file
    path('', include('codebase.urls'))

Step 8

In the codebase folder, create a file and name it

from django.urls import path
#importing home function from
from .views import home

urlpatterns = [
    path('', home, name='home'),

Step 9

Run the following commands:

python makemigrations

python migrate

Step 10

Run the command below:

python runserver

Then, go to to access the homepage.




Njoku Ifeanyi Gerald

View all Courses

Keep Exploring