Articles → DJANGO → Detail View In Django
Detail View In Django
Implementation
- In views.py, create a class for detail view
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()
- Create a HTML template for details view
- Add an entry in urls.py
from django.contrib import admin
from django.urls import path
from TestModule.views import MyListView, MyDetailView
urlpatterns = [path('admin/', admin.site.urls), path('mylist',
MyListView.as_view()), path('<int:pk>/',
MyDetailView.as_view())]
Output
Click to Enlarge