Articles → DJANGO → List page in Django

List page in Django






Scenario







Example






from django.http  import HttpResponse
from django.shortcuts import render
from .models import MyNewScreen

# Create your views here.
def home(request):
    return render(request, "template1.html",{})

def about(request):
    return render(request, "about.html",{})   

def get_list(request):
    template_name = 'get_list.html'
    queryset = MyNewScreen.objects.all()
    context = {
        "list": queryset
        }
    return render(request, template_name, context)




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




from django.contrib import admin
from django.urls import path
from TestModule.views import home
from TestModule.views import about
from TestModule.views import get_list

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', home),
    path('about', about),
    path('get_list',get_list),





Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, January 08, 2020

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250