Program 3
Develop a simple Django app that displays an unordered list of fruits and ordered list of selected students for an event
views.py
from django.shortcuts import render
# Create your views here.
def prog3func(request):
context = {
'fruits' : ['Apple','Banana','Cherry'],
'students' : ['Ram','Sam','Tam','Zam']
}
return render(request,'listy.html',context)
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('listy', views.prog3func, name='p3'),
]
templates/listy.html
<!DOCTYPE html>
<html>
<head>
<title>Program 3</title>
<style>
body {
background-color: orange;
font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif;
}
ul {
color: blue;
list-style-type: square;
}
ol {
color: green;
list-style-type: upper-roman;
}
</style>
</head>
<body>
<h1>Unordered Fruits List</h1>
<ul>
{{fruits | unordered_list}}
</ul>
<br><br>
<h1>Ordered Students List</h1>
<ol>
{% for student in students %}
<li>Student #{{forloop.counter}} is {{student}}</li>
{% endfor %}
</ol>
</body>
</html>