Django DetailView example


models.py

the model that we want to make a page for each query dynamically


# models.py
class test(models.Model):
    firstname = models.CharField(max_length=300)
    last_name = models.CharField(max_length=300)


views.py


#views.py
class test_detail(DetailView):
    model = test # model
    template_name = 'test.html' # template path
    slug_field = 'firstname' # slug field
    

urls.py


#url.py
path('<slug:slug>/', test_detail.as_view(), name='test_detail'), #slug = slug field


test.html


#test.html
<!DOCTYPE html>
<html>
<head>
<title>Detailview</title>
</head>
<body>
<h1>hello {{object.firstname}} !</h1>
</body>
</html>

We have added some quries in the "test" model


result

English today is not an art to be mastered it's just a tool to use to get a result