[Django]-What is a good way to get the dynamic title of a page in Django?

9👍

The easiest way to do this is:
Insert the following code in your base.html

#base.html
{% block title %} {% endblock %}

and following in your index or any Html file with your title

#index.html
{% extends 'base.html'%}
{% block title %} My Page Title {% endblock %}

0👍

Place your context object key in double paranthesis.
Lets take am making a dynamic teacher’s page in a school management system

#urls.py
path("teacher/<str:pk>/",views.teacher,name="teacher"),

The vew

#view
def teacher(request,pk):
    teacher = Teacher.objects.get(id=pk)
    context= {"teacher":teacher}
    return render(request,'main/teacher.html',context)

The template

 <title>{{teacher.fname}} Page</title>

Leave a comment