0% found this document useful (0 votes)
7 views5 pages

4.lab Program

The document outlines the steps to create a Django project named 'mywebsite' and an app called 'main'. It includes instructions for setting up HTML templates for a layout, home, about, and contact pages, along with defining URLs and views for each page. The document also emphasizes the creation of a navigation menu in the layout and the inclusion of app URLs in the main project settings.

Uploaded by

Deepika
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)
7 views5 pages

4.lab Program

The document outlines the steps to create a Django project named 'mywebsite' and an app called 'main'. It includes instructions for setting up HTML templates for a layout, home, about, and contact pages, along with defining URLs and views for each page. The document also emphasizes the creation of a navigation menu in the layout and the inclusion of app URLs in the main project settings.

Uploaded by

Deepika
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

4. Develop a layout.

html 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. <header>
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. {% block content %}
19.
20. <h1> Welcome to Main Page </h1>
21.
22. {% endblock %}
23.
24. <p> Welcome to RLJIT Doddaballpur .</p>
25.
26. </body>
27. </html>

[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