Articles → DJANGO → Listview in django

Listview in django






Implementation






from django.http  import HttpResponse
from django.shortcuts import render
from .models import MyNewScreen
from django.views.generic import ListView


class MyListView(ListView):
    template_name = "get_list.html"
    queryset = MyNewScreen.objects.all()




from django.contrib import admin
from django.urls import path
from TestModule.views import (
    MyListView,
    )

urlpatterns = [
    path('admin/', admin.site.urls),
    path('mylist',MyListView.as_view()),
    
]




<html>
<body>
    <h1>My List</h1>
    <ul>
        {% for obj in object_list %}
            <li> {{ obj.name}} </li>
        {% endfor %}
    </ul>
</body>
</html>



Output



Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Saturday, January 18, 2020

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250