0% found this document useful (0 votes)
22 views6 pages

Mod2 pgm12

Uploaded by

Bhargavi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views6 pages

Mod2 pgm12

Uploaded by

Bhargavi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

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.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.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),
]

Template files: layout.html


<html>
<title>{% block title %} {% endblock %} </title>
<style type="text/css">
nav {background-color: lightblue;padding:10px}
</style>
<body>
<nav>
<a href="/home/">Home</a>|
<a href="/aboutus/">About Us</a>|
<a href="/contactus/">Contact Us</a>|
</nav>
<section>
{% block content %}{% endblock %}
</section>
<footer>
<hr>
&copy; AIML, Developed by ABC, Inc.
</footer>
</body>
</html>

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 %}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy