s
s
view.py
def home(request):
fruits = [‘orange’ , ’apple’ , ’mango’]
students = [‘john’ , ‘jani’ , ‘janardhan’]
context={‘students’ : students , ‘fruits’ : fruits}
return render (request, ‘home.html’, context)
home.html
<HTML>
<body>
<h1>FRUITS</h1>
<ul>
{% for fruit in fruits %}
<li>{{fruit}}</li>
{% end for%}
</ul>
<h1>STUDENTS</h1>
<ol>
{% for student in students %}
<li>{{student}}</li>
{% end for%}
</ul>
</body>
</html>
urls.py
urlpa erns = [
path(‘home/', views.home),
]
LAYOUT PROGRAM
layout.html
<HTML>
<TITLE>{% block tle %} {% end block %}</TITLE>
<body>
<a href = ‘home/’>HOME</a>
<a href = ‘about/’>ABOUT</a>
<a href = ‘contact/’>CONTACT</a>
<sec on>{% block content %} {% end block %}
</body>
</html>
about.html
{% extends ‘myapp/layout.html’ %}
{% block tle %}ABOUT {% end block %}
{% block content %} THIS IS ABOUT PAGE{% end block %}
contact.html
{% extends ‘myapp/layout.html’ %}
{% block tle %}CONTACT {% end block %}
{% block content %} THIS IS CONTACT PAGE{% end block %}
home.html
{% extends ‘myapp/layout.html’ %}
{% block tle %}HOME {% end block %}
{% block content %} THIS IS HOME PAGE{% end block %
view.py
def home(request):
retrun render(request , ‘myapp/home.html’)
def about(request):
retrun render(request , ‘myapp/about.html’)
def contact(request):
retrun render(request , ‘myapp/contact.html’)
urls.py
urlpa erns = [
path(‘home/', views.home),
path(‘about/', views.about),
path(‘contact/', views.contact),
]