0% found this document useful (0 votes)
123 views10 pages

Fullstack Development Lab Programs-2

Ful stack web development lab program 2
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)
123 views10 pages

Fullstack Development Lab Programs-2

Ful stack web development lab program 2
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

Fullstack Development Lab Programs: Module 2

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

[Link]
from datetime import date
from [Link] import HttpResponse from
[Link] import render
from [Link] import Context, Template

# Create your views here.


def showlist(request):
fruits=["Mango","Apple","Bananan","Jackfruits"]
student_names=["Tony","Mony","Sony","Bob"] return
render(request,'[Link]',{"fruits":fruits,"student_names":student_names}
)

[Link]

from [Link] import admin


from [Link] import path, re_path
from [Link] import check_number, current_date_time from
[Link] import four_hours_after, four_hours_before from
[Link] import n_hours_after,display_string
from [Link] import create_table_of_squares,vc,find_mode from
[Link] import template_test,showlist
urlpatterns = [
path('admin/', [Link]),
path('cdt/', current_date_time),
path('fha/',
four_hours_after),path('fhb/',
four_hours_before),
path('nha/<int:num>',
n_hours_after),
path('display_string/<slug:sentence>', display_string),
re_path('check_number/(\d){1,2}/',check_number),
path('cts/<int:s>/<int:n>', create_table_of_squares),
path('vc/<str:sentence>', vc),
path('find_mode/<str:listofnum>', find_mode),
path('template_test/', template_test), path('showlist/',
showlist),
]

Template HTML file (inside ap2/templates subfolder)


[Link]
<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>

Output:
2. 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.

[Link]
from datetime import date
from [Link] import HttpResponse from
[Link] import render
from [Link] import Context, Template def
home(request):
return render(request,'[Link]')

def aboutus(request):
return render(request,'[Link]')

def contactus(request):
return render(request,'[Link]')

[Link]
from [Link] import admin
from [Link] import path, re_path
from [Link] import check_number, current_date_time from
[Link] import four_hours_after, four_hours_before from
[Link] import n_hours_after,display_string
from [Link] import create_table_of_squares,vc,find_mode from
[Link] import template_test,showlist,list_of_subjects from
[Link] import aboutus,home,contactus

urlpatterns = [
path('admin/', [Link]), path('cdt/',
current_date_time), path('fha/',
four_hours_after), path('fhb/'
four_hours_before), path('nha/<int:num>',
n_hours_after),
path('display_string/<slug:sentence>', display_string),
re_path('check_number/(\d){1,2}/',check_number),

path('cts/<int:s>/<int:n>', create_table_of_squares),
path('vc/<str:sentence>', vc),
path('find_mode/<str:listofnum>', find_mode),
path('template_test/', template_test), path('showlist/',
showlist), path('list_of_subjects/', list_of_subjects),
path('aboutus/', aboutus),
path('home/', home),
path('contactus/', contactus),
]

Template files:
[Link]
<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>

[Link]
{% extends '[Link]' %}
{% block title %} Home
{% endblock %}
{% block content %}
<h2>This is the home page</h2>
{% endblock %}
[Link]
{% extends '[Link]' %}
{% block title %} About
Us
{% endblock %}
{% block content %}
<h2>We are DJango developers</h2>
{% endblock %}

[Link]
{% extends '[Link]' %}
{% block title %}
Contact us
{% endblock %}
{% block content %}
<h2>Out phone: 9900923050 <br> Address:
Navule JNNCE</h2>
{% endblock %}

Output:
It should also display list of students registered for any selected course.
Create students and course as models with enrolment as ManyToMany field

[Link]
from [Link] import models

# Create your models here. class


Course([Link]):
course_code=[Link](max_length=40)
course_name=[Link](max_length=100) course_credits=[Link]()

class Student([Link]):
student_usn=[Link](max_length=20)
student_name=[Link](max_length=100)
student_sem=[Link]()
enrolment=[Link](Course)
[Link] inside templates folder
<html>
<body>
<form method="post" action="">
{% csrf_token %}
Student Name
<select name="sname">
{%for student in students %}
<option value="{{[Link]}}">{{student.student_name}}</option>
{% endfor %}
</select><br> Course
Name
<select name="cname">
{%for course in courses %}
<option value="{{[Link]}}">{{course.course_name}}</option>
{% endfor %}

</select><br>
<input type="submit" value="Enroll">
</form>
</body>
</html>

[Link]
from [Link] import HttpResponse from
[Link] import render

from [Link] import Course, Meeting, Student def

reg(request):
if [Link] == "POST":
sid=[Link]("sname")
cid=[Link]("cname")
student=[Link](id=sid)
course=[Link](id=cid)
res=[Link](id=cid) if
res:
return HttpResponse("<h1>Student already enrolled</h1>")
[Link](course)
return HttpResponse("<h1>Student enrolled successfully</h1>") else:
students=[Link]()
courses=[Link]()
return render(request,"[Link]",{"students":students,
"courses":courses})

[Link]
from [Link] import admin
from [Link] import path, re_path
from [Link] import check_number, current_date_time from
[Link] import four_hours_after, four_hours_before from
[Link] import n_hours_after,display_string
from [Link] import create_table_of_squares,vc,find_mode from
[Link] import template_test,showlist,list_of_subjects from
[Link] import aboutus,home,contactus,getpos,stable
from [Link] import insert_demo,update_demo,delete_demo,retreive_demo from
[Link] import reg
urlpatterns = [
path('admin/', [Link]), path('cdt/',
current_date_time), path('fha/',
four_hours_after), path('fhb/',
four_hours_before), path('nha/<int:num>',
n_hours_after),
path('display_string/<slug:sentence>', display_string),
re_path('check_number/(\d){1,2}/',check_number),
path('cts/<int:s>/<int:n>', create_table_of_squares),
path('vc/<str:sentence>', vc),
path('find_mode/<str:listofnum>', find_mode),
path('template_test/', template_test), path('showlist/',
showlist),
path('list_of_subjects/', list_of_subjects),
path('aboutus/', aboutus),
path('home/', home), path('contactus/',
contactus), path('getpos/', getpos),
path('stable/', stable),
path('insert_demo/', insert_demo),
path('update_demo/', update_demo),
path('delete_demo/', delete_demo),
path('retreive_demo/', retreive_demo),
path('reg/', reg),]

Database input: Insert student and courses record in


phpMyAdmin
BackEnd

If you try again, you will get

You might also like