django code 2 pg 10 to 20
django code 2 pg 10 to 20
django code 2 pg 10 to 20
.
.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATES_DIR],
'APP_DIRS': True,
.
.
.
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/
STATIC_URL = 'static/'
STATICFILES_DIRS=[STATIC_DIR]
urlpatterns = [
path('admin/', admin.site.urls),
path('course/',include('course.urls')),
path('fees/',include('fees.urls')),
path('',views.home),
]
8. Views.py (ucs6)
def home(request):
return render(request, 'home.html',{'data':'Home Page'})
9. Create templates folder in ucs6
10. home.html (ucs6/templates)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
</head>
<body>
<h1>Welcome to {{data}}</h1>
</body>
</html>
11. Create sta c folder inside ucs6
12. Create css, images and js folder inside sta c
13. Create style.css in css folder
img{
width: 350px;
height: 350px;
border: solid 2px;
border-radius: 50%;
}
body{
background-color: cadetblue;
}
14. Copy two images in images folder named dj1.png and dj2.jpeg for this project.
15. Create all.js file in js folder
function display(){
alert("Main Java Script Hoon!!!")
}
16. Urls.py (course)
urlpatterns = [
path('learn_dj/',views.learn_django),
path('login/',views.tut_django,name='tutdj'),
]
17. Views.py(course)
def tut_django(request):
return render(request,'course/tutorials.html',{'data':'Django Tutorials
Page'})
18. Create templates/course (course)
19. Info.html (course/templates/course)
<!DOCTYPE html>
{% load static %}
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{data}}</title>
<style>
body{
background-color: rgb(255, 242, 127);
}
</style>
<hr>
<a href="{% url 'tutdj' %}">Django Tutorial</a><br>
<a href="{% url 'tutdj' %}">Django Tutorial</a><br>
<a href="{% url 'tutdj' %}">Django Tutorial</a><br>
<a href="{% url 'tutdj' %}">Django Tutorial</a><br>
<hr>
<form action="">
<input type="button" value="Click Me" onclick="display()" >
</form>
</body>
</html>
20. Tutorials.html (course/templates/course)
<!DOCTYPE html>
{% load static %}
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{data}}</title>
<style>
body{
background-color: rgb(255, 242, 127);
}
</style>
</head>
<body>
<h1>Django Tutorials</h1>
<hr>
<hr>
<a href="../learn_dj">Learn Django</a><br>
</body>
</html>
21. Urls.py (fees)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{data}}</title>
</head>
<body>
<h1>Welcome to {{data}}</h1>
</body>
</html>
Django Template Language
import os
6. Urls.py (ucs8)
urlpatterns = [
path('admin/', admin.site.urls),
path('cor/', include('course.urls')),
]
7. Urls.py (course)
#Example 1
def learn_django(request):
return render(request, 'course/courseone.html', {'nm':'Django'})
"""
#Example 2
def learn_django(request):
cname = 'Django'
duration = '4 Months'
seats = 10
django_details = {'nm':cname, 'du':duration, 'st':seats}
return render(request, 'course/courseone.html', django_details)
"""
"""
#Example 3
def learn_django(request):
return render(request, 'course/courseone.html', {'nm':'Django is
awesome'})
"""
"""
#Example 4
def learn_django(request):
d = datetime.now()
return render(request, 'course/courseone.html', {'dt':d})
"""
"""
#Example 5
def learn_django(request):
return render(request, 'course/courseone.html', {'p1':56.24321,
'p2':56.000, 'p3':56.37000})
"""
"""
#Example 6
def learn_django(request):
return render(request, 'course/courseone.html', {'nm':True})
"""
"""
#Example 7
def learn_django(request):
return render(request, 'course/courseone.html', {'nm':'Django'})
"""
"""
#Example 8
def learn_django(request):
return render(request, 'course/courseone.html', {'nm':'Django',
'st':5})
"""
"""
#Example 9
def learn_django(request):
student = {'names': ['Rahul', 'Sonam', 'Raj','Anu']}
return render(request, 'course/courseone.html', student)
"""
"""
#Example 10
def learn_django(request):
stu = {'stu1': {'name': 'Rahul', 'roll':101},
'stu2': {'name': 'Sonam', 'roll':102},
'stu3': {'name': 'Raj', 'roll':103},
'stu4': {'name': 'Anu', 'roll':104},
}
students = {'student':stu}
return render(request, 'course/courseone.html', students)
"""
"""
#Example 11
def learn_django(request):
data = {'name': 'Rahul', 'roll':101}
return render(request, 'course/courseone.html', {'data':data})
"""
"""
#Example 12
def learn_django(request):
data = {'stu1': {'name': 'Rahul', 'roll':101},
'stu2': {'name': 'Sonam', 'roll':102},
'stu3': {'name': 'Raj', 'roll':103},
'stu4': {'name': 'Anu', 'roll':104},
}
return render(request, 'course/courseone.html', {'data':data})
"""
9. Templates/course/courseone.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
body {
background-color: black;
color: seashell;
}
</style>
<title>Django</title>
</head>
<body>
<h2>Example 1</h2>
<h3>Hello {{nm}}</h3>
<!--<h2>Example 3.2</h2>
<h3>{{nm|default:'nothing'}}</h3> -->
<h2>Example 4.2</h2>
<h3>{{dt|date:"D d M Y"}}</h3>
<h2>Example 4.3</h2>
<h3>{{dt|time:"H:i"}}</h3>
<h2>Example 4.4</h2>
<h3>{{dt|date:"SHORT_DATE_FORMAT"}}</h3>
<h2>Example 4.5</h2>
<h3>{{dt|time:"TIME_FORMAT"}}</h3> -->
<h2>Example 5.2</h2>
<h3>{{p1|floatformat}}</h3>
<h3>{{p2|floatformat}}</h3>
<h3>{{p3|floatformat}}</h3>
<h2>Example 5.3</h2>
<h3>{{p1|floatformat:3}}</h3>
<h3>{{p2|floatformat:3}}</h3>
<h3>{{p3|floatformat:3}}</h3>
<h2>Example 5.4</h2>
<h3>{{p1|floatformat:0}}</h3>
<h3>{{p2|floatformat:0}}</h3>
<h3>{{p3|floatformat:0}}</h3>
<h2>Example 5.5</h2>
<h3>{{p1|floatformat:-3}}</h3>
<h3>{{p2|floatformat:-3}}</h3>
<h3>{{p3|floatformat:-3}}</h3> -->
<h2>Example 8.2</h2>
{% if nm or st %}
<h3>{{st}} seats are available for {{nm}} course</h3>