0% found this document useful (0 votes)
9 views7 pages

Program 3 & 4

fullstackfull

Uploaded by

iliyaz pasha
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)
9 views7 pages

Program 3 & 4

fullstackfull

Uploaded by

iliyaz pasha
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

3.

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

[Link]

<html>
</head>
<title>Home Page</title>
</head>
<body>

<h1>List of Fruits</h1>

<ul>
{% for item in fruit_list %}
<li>{{item}}</li>
{%endfor%}
</ul>

<h1>List of students</h1>

<ul>
{% for student in student_list %}
{%if [Link] > 75%}
<li>{{[Link]}}</li>
{%endif%}
{%endfor%}
</ul>
</body>
</html>

[Link]

from [Link] import HttpResponse


from [Link] import render

def homepage(request):
fruits=['Apple','Banana','Orange','Pineapple']

students = [
{'name': 'Harish', 'score': 85},
{'name': 'Briana', 'score': 70},
{'name': 'John', 'score': 95},
{'name': 'Arul', 'score': 60},
]
context={'fruit_list':fruits,'student_list':students,}
return render(request,"[Link]",context)

[Link]
from [Link] import admin
from [Link] import path
from .views import homepage

urlpatterns = [
path('admin/', [Link]),
path('home/',homepage),
]

Output
4. Develop a [Link] with a suitable header (containing navigation menu) and
footer with copyright and developer information. Inherit this [Link] and create
3 additional pages: contact us, About Us and Home page of any website

1. Create a Django project: django-admin startproject mywebsite


2. Enter into Django project mywesite : cd mywebsite
3. Create a Django app: python [Link] startapp main
4. Add the app to the project: Open mywebsite/[Link] and add 'main' to INSTALLED_APPS:

5. Create a templates directory: Create a templates directory inside the main app folder

6. Create [Link] , [Link], [Link] and [Link] files in templates folder as

[Link]
1. <!DOCTYPE html>
2. <html lang="en">
3. <head>
4. <title>{% block title %}My Website{% endblock %}</title>
5.
6. </head>
7. <body>
8.
9.
10. <ul>
11. <li><a href="{% url 'mainpage' %}">layout</a></li>
12. <li><a href="{% url 'home' %}">Home</a></li>
13. <li><a href="{% url 'about' %}">About Us</a></li>
14. <li><a href="{% url 'contact' %}">Contact Us</a></li>
15.
16. </ul>
17.
18.
19. {% block content %}
20.
21. <h1> Welcome to Main Page </h1>
22.
23. {% endblock %}
24.
25. <p> Welcome to RLJIT Doddaballpur .</p>
26.
27. </body>
28. </html>
29.

[Link]

{% extends '[Link]' %}

{% block title %}About Us - My Website{% endblock %}

{% block content %}

<h1>About Us</h1>

<p>This is the About Us page.</p>

{% endblock %}

[Link]

{% extends '[Link]' %}

{% block title %}Contact Us - My Website{% endblock %}

{% block content %}

<h1>Contact Us</h1>

<p>This is the Contact Us page.</p>


{% endblock %}

[Link]

{% extends '[Link]' %}

{% block title %}Home - My Website{% endblock %}

{% block content %}

<h1>Welcome to My Website</h1>

<p>This is the home page.</p>

{% endblock %}

7. Create URLs in the app: Open main/[Link] and add the following content:

1. from [Link] import path


2. from . import views
3.
4. urlpatterns = [
5.
6. path('mainpage/', [Link], name='mainpage'),
7. path('home/', [Link], name='home'),
8. path('about/', [Link], name='about'),
9. path('contact/', [Link], name='contact'),
10. ]
11.

8. Include app URLs in the project: Open mywebsite/[Link] and modify it to include the app's URLs:

from [Link] import admin

from [Link] import path, include

urlpatterns = [

path('admin/', [Link]),

path('', include('[Link]')),

]
9. Define views: Open main/[Link] and define the views for the pages
1. from [Link] import render
2.
3. def mainpage(request):
4. return render(request, '[Link]')
5.
6. def home(request):
7. return render(request, '[Link]')
8.
9. def about(request):
10. return render(request, '[Link]')
11.
12. def contact(request):
13. return render(request, '[Link]')

Output:
Tree-structure for Reference

You might also like