Articles → DJANGO → List Page In Django

List Page In Django



  1. Create a function get_list in in TestModule
  2. 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)

  3. Create a HTML template
  4. <html>
            <h1>My List</h1>
            {% for obj in list %}
                <li> {{}} </li>
            {% endfor %}

  5. Add an entry in URLs.
  6. 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("", home),
        path("about", about),
        path("get_list", get_list),

Picture showing the output of the list page in Django
Click to Enlarge

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


Your Email Id  
Query/FeedbackCharacters remaining 250