Detail View - Function Based Views Django - GeeksforGeeks
Detail View - Function Based Views Django - GeeksforGeeks
Detail View - Function Based Views Django - GeeksforGeeks
Write & Earn DSA Data Structures Algorithms Interview Preparation Data Science Topic
Detail View refers to a view (logic) to display a par ticular instance of a table from the
database with all the necessar y details. It is used to display multiple types of data on
a single page or view, for example, profile of a user. Django provides extra-ordinar y
suppor t for Detail Views but let ’s check how it is done manually through a function-
based view. This ar ticle revolves around Detail View which involves concepts such as
For Detail View, we need a project with some models and multiple instances which
will be displayed.
Illustration of How to create and use Detail view using an Example. Consider a
Refer to the following ar ticles to check how to create a project and an app in
Django.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge
that you have read and understood our
Cookie Policy &
Privacy Policy
Af ter you have a project and an app, let ’s create a model of which we will be creating
Got It !
instances through our view. In geeks/models.py,
https://www.geeksforgeeks.org/detail-view-function-based-views-django/ 1/8
12/3/22, 8:37 PM Detail View - Function based Views Django - GeeksforGeeks
Login Register
AD -44% -63% -40% -32% -35% -69% -3
Tai nghe không … Máy lọc không … Tai nghe không … Tai nghe Blueto… Tai nghe Blueto… Tai nghe Blueto… T
P ython3
Af ter creating this model, we need to run two commands in order to create Database
Now let ’s create some instances of this model using shell, run form bash,
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge
that you have read and understood our
Cookie Policy &
Privacy Policy
Enter following commands
Got It !
https://www.geeksforgeeks.org/detail-view-function-based-views-django/ 2/8
12/3/22, 8:37 PM Detail View - Function based Views Django - GeeksforGeeks
title="title1",
description="description1").save()
>>> GeeksModel.objects.create(
title="title2",
description="description2").save()
>>> GeeksModel.objects.create(
title="title3",
description="description3").save()
Now we have ever ything ready for back end. Verif y that instances have been created
from http://localhost:8000/admin/geeks/geeksmodel/
For detail_view one would need some identification to get a par ticular instance of the
model. Usually it is unique primar y key such as id. To specif y this identification we
P ython3
https://www.geeksforgeeks.org/detail-view-function-based-views-django/ 3/8
12/3/22, 8:37 PM Detail View - Function based Views Django - GeeksforGeeks
path('<id>', detail_view ),
Start Your Coding Journey Now!
] Login Register
P ython3
html
<div class="main">
<!-- Specify fields to be displayed -->
{{ data.title }}<br/>
{{ data.description }}<br/>
</div>
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge
that you have read and understood our
Cookie Policy &
Privacy Policy
Got It !
https://www.geeksforgeeks.org/detail-view-function-based-views-django/ 4/8
12/3/22, 8:37 PM Detail View - Function based Views Django - GeeksforGeeks
Bingo..!! Detail view is working fine. One can also display selected fields according to
type of usage required in multiple forms. Of ten it is not the id which is used to define
the detail view it is the slug. To know more about slug and SlugField visit – Add the
Like 9
Previous Next
Related Articles
Got It !
3. Delete View - Function based Views Django
https://www.geeksforgeeks.org/detail-view-function-based-views-django/ 5/8
12/3/22, 8:37 PM Detail View - Function based Views Django - GeeksforGeeks
Start
4. Your Coding
List View Journey
- Function Now!Django
based Views Login Register
Ar ticle Contributed By :
NaveenArora
@NaveenArora
https://www.geeksforgeeks.org/detail-view-function-based-views-django/ 6/8
12/3/22, 8:37 PM Detail View - Function based Views Django - GeeksforGeeks
Company Learn
About Us DSA
Careers Algorithms
In Media Data Structures
Contact Us SDE Cheat Sheet
Privacy Policy Machine learning
Copyright Policy CS Subjects
Advertise with us Video Tutorials
Courses
News Languages
Top News
Python
Technology
Java
Work & Career
CPP
Business
Golang
Finance
C#
Lifestyle
SQL
Knowledge
Kotlin
https://www.geeksforgeeks.org/detail-view-function-based-views-django/ 7/8
12/3/22, 8:37 PM Detail View - Function based Views Django - GeeksforGeeks
@geeksforgeeks
, Some rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge
that you have read and understood our
Cookie Policy &
Privacy Policy
Got It !
https://www.geeksforgeeks.org/detail-view-function-based-views-django/ 8/8