Mod2 pgm12
Mod2 pgm12
Develop a simple Django app that displays an unordered list of fruits and ordered list of selected students
for an event
Views.py
URLS.py
from django.contrib import admin
from django.urls import path, re_path
from ap2.views import template_test,showlist
urlpatterns = [
path('showlist/', showlist),
]
Template HTML file (inside ap2/templates subfolder)
showlist.html
<html>
<style type="text/css">
#i1 {background-color: lightgreen;color:brown;display:table}
#i2 {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="i2">Ordered list of Students</h1>
<ol>
{% for student in student_names %}
<li>{{ student }}</li>
{% endfor %}
</ol>
</body>
</html>
2. Develop a layout.html with a suitable header (containing navigation menu) and footer with copyright and
developer information. Inherit this layout.html and create 3 additional pages: contact us, About Us and
Home page of any website.
Views.py
from datetime import date
from django.http import HttpResponse
from django.shortcuts import render
from django.template import Context, Template
def home(request):
return render(request,'home.html')
def aboutus(request):
return render(request,'aboutus.html')
def contactus(request):
return render(request,'contactus.html')
URLS.py
from django.contrib import admin
from django.urls import path, re_path
from ap2.views import aboutus,home,contactus
urlpatterns = [
path('aboutus/', aboutus),
path('home/', home),
path('contactus/', contactus),
]
home.html aboutus.html
{% extends 'layout.html' %} {% extends 'layout.html' %}
{% block title %} {% block title %}
Home About Us
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<h2>This is the home page</h2> <h2>We are DJango developers</h2>
{% endblock %} {% endblock %}
contactus.html
{% extends 'layout.html' %}
{% block title %}
Contact us
{% endblock %}
{% block content %}
<h2>Out phone: 9900923050 <br>
Address: Navule JNNCE</h2>
{% endblock %}