Develop a Django app that displays an unordered list of fruits and ordered list of selected students for an event.

Develop a Django app that displays an unordered list of fruits and ordered list of selected students for an event.

Program:-

views.py:-

from datetime import date
from django.http import HttpResponse
from django.shortcuts import render
from django.template import Context, Template

# Create your views here.
def showlist(request):
    fruits=["Mango", "Apple", "Bananan", "Jackfruits"]
    student_names=["Tony", "Mony", "Sony", "Bob"]
    return render(request, 'showlist.html', {"fruits": fruits, "student_names": student_names})

urls.py:-

from django.urls import path, re_path
from ap2.views import showlist
urlpatterns = [
    path('showlist/', showlist),
]

templates/showlist.html:-

<html>
    <style type="text/css">
        #11 {background-color: lightgreen; color: brown; display: table;}
        #12 {background-color: black; color: yellow;}
    </style>
    <body>
        <h1 id="i1">Unordered list of fruits</h1>
        <ul>
            {% for fruit in fruits %}
                <li>{{ fruit }}</li>
            {% endfor %}
        </ul>
        <h1 id="12">Ordered list of Students</h1>
        <ol>
            {% for student in student_names %}
                <li>{{ student }}</li>
            {% endfor %}
        </ol>
    </body>
</html>

Leave a Reply

Your email address will not be published. Required fields are marked *