Articles → DJANGO → Detail View In Django

Detail View In Django


  1. In, create a class for detail view
  2. from django.http import HttpResponse
    from django.shortcuts import render
    from models import MyNewScreen
    from django.views.generic import ListView
    from django.views.generic import DetailView
    class MyListView(ListView):
        template_name = 'get_list.html'
        queryset = MyNewScreen.objects.all()
    class MyDetailView(DetailView):
        template_name = 'detail.html'
        queryset = MyNewScreen.objects.all()

  3. Create a HTML template for details view
  4. <h1>{{}}</h1>

  5. Add an entry in
  6. from django.contrib import admin
    from django.urls import path
    from TestModule.views import MyListView, MyDetailView
    urlpatterns = [path('admin/',, path('mylist',
                   MyListView.as_view()), path('<int:pk>/',


Picture showing the output of detail view in django
Click to Enlarge

Posted By  -  Karan Gupta
Posted On  -  Tuesday, January 21, 2020


Your Email Id  
Query/FeedbackCharacters remaining 250