Articles → DJANGO → Detail view in django

Detail view in django






Implementation






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()




<h1>{{object.name}}</h1>




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


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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250