SlideShare a Scribd company logo
Django 
victor.miclo.kisi
MTV??
Model
Template
View
views.py 
def some_view(request): 
return render_to_response(“path/to/template.html”, 
{}, RequestContext(request))
HTML 
<html> 
<head> 
<title>Hello world</title> 
</head> 
<body> 
<p>Hi</p> 
</body> 
</html>
Tags in HTML 
● Paragraphs 
● Headers 
● Divs 
● Section 
● asection 
● etc. 
● See W3C tutorials and plenty of Online 
tutorials
CSS (Cascading Style Sheets) 
`style.css` 
p{ 
color: red; 
}
CSS (Cascading Style Sheets) 
`style.css` 
.food_section{ 
color: red; 
}
CSS (Cascading Style Sheets) 
`style.css` 
#food_section{ 
color: red; 
}
Bootstrap 
`http://getbootstrap.com` 
<head> 
<link rel=”styleshet” href=”path/to/bootstrap.css”> 
</head> 
<body> 
...some code… 
<script src=”path/to/bootstrap.js”></script>
Google Fonts 
`http://www.google.com/fonts` 
<head> 
<link rel=”styleshet” href=”path/to/bootstrap.css”> 
<link href='http://fonts.googleapis.com/css? 
family=Open+Sans' rel='stylesheet' type='text/css'> 
</head> 
<body>...</body>
URLs.. 
What is URL?
URLs.. 
Maps your “view functions” to a URL. 
● someone visits a URL 
● URL tells django what to do 
● Django returns a set of HTML (templates)
Templates [part 1] 
Just HTML… take it EASY!
Templates 
mysite 
⇒ mysite 
===> templates/mysite 
===> [other folders] 
⇒ app1 
===> templates/app1 
===> [other folders] 
⇒ app2 
===> templates/app2 
===> [other folders]
forms [Non-model based] 
● Create `forms.py` in your Django Application 
● import the Form class 
● define what you’ll collect
forms [Non-model based] 
from django import forms 
class MessageForm(forms.Form): 
number = forms.CharField() 
text = forms.CharField()
Hooking up forms in Views 
from form import MessageForm 
def new_message(request): 
form = MessageForm() 
if request.method == “POST”: 
form = MessageForm(request.POST) 
if form.valid(): 
form.save() # save 
else: 
pass # handle errors! 
return render_to_response(‘messages/new.html’, {‘form’:form}, 
RequestContext(request))
Shortcuts!!!
forms [Model based] 
● Create `forms.py` in your Django Application 
● import the Form class 
● define what you’ll collect
forms [Model based] 
from django import forms 
from .models import Message 
class MessageForm(forms.ModelForm): 
model = Message
Hooking up forms in Views (similar) 
from form import MessageForm 
def new_message(request): 
form = MessageForm() 
if request.method == “POST”: 
form = MessageForm(request.POST) 
if form.valid(): 
form.save() # save 
else: 
pass # handle errors! 
return render_to_response(‘messages/new.html’, {‘form’:form}, 
RequestContext(request))
Hooking up forms in HTML 
<form
Some advanced topics...
Template inheritance 
Base HTML file 
e.g. base.html 
Profile page 
e.g. profile.html 
Messages page 
e.g. messages.html
Template inheritance 
Base HTML file 
e.g. base.html 
Profile page 
e.g. profile.html 
Base HTML has your 
site-wide designs and 
you don’t have to repeat 
the design on different 
pages. 
Messages page 
e.g. messages.html
Template inheritance 
Base HTML file 
e.g. base.html 
code sample... 
<html> 
<head> 
<!-- CSS or js here --> 
</head> 
<body> 
{% block content %} 
{% endblock %} 
</body> 
</html>
Template inheritance 
{% extends “base.html” %} 
{% block content %} 
<div> 
Hi {{ name }}. You are seeing your profile. 
</div> 
{% endblock %} 
Profile page 
e.g. profiles.html 
code sample...
What next…?
● Do the django girls tutorial 
● Do the 6 part django tutorial (http: 
//djangoproject.com) 
● Google a lot! 
● Do many projects.. 
● Check out TDD

More Related Content

What's hot

Asp
AspAsp
AngularJs - Part 3
AngularJs - Part 3AngularJs - Part 3
AngularJs - Part 3
Nishikant Taksande
 
Building Templates for Joomla
Building Templates for JoomlaBuilding Templates for Joomla
Building Templates for Joomla
JoomlaDay Australia
 
Css Founder.com | Cssfounder Org
Css Founder.com | Cssfounder OrgCss Founder.com | Cssfounder Org
Css Founder.com | Cssfounder Org
Css Founder
 
Bad Form @ JSConf Asia 2014
Bad Form @ JSConf Asia 2014Bad Form @ JSConf Asia 2014
Bad Form @ JSConf Asia 2014
cliener
 
Ddpz2613 topic6 frame
Ddpz2613 topic6 frameDdpz2613 topic6 frame
Ddpz2613 topic6 frame
Mohamad Sahiedan
 
Element Styles and Positioning
Element Styles and PositioningElement Styles and Positioning
Element Styles and Positioning
alexisabril
 
PHP Forms PHP 05
PHP Forms PHP 05PHP Forms PHP 05
PHP Forms PHP 05
Spy Seat
 
Rounded Shaped Box Example 1
Rounded Shaped Box Example 1Rounded Shaped Box Example 1
Rounded Shaped Box Example 1
Sibananda Panda
 
Java script functions
Java script   functionsJava script   functions
Java script functions
AbhishekMondal42
 
Drupal Cafe №5 Харьков. Drupal 7 Views 3.
Drupal Cafe №5 Харьков. Drupal 7 Views 3.Drupal Cafe №5 Харьков. Drupal 7 Views 3.
Drupal Cafe №5 Харьков. Drupal 7 Views 3.
Alexey Gaydabura
 
Javascript
JavascriptJavascript
Javascript
Jitendra Negi
 

What's hot (12)

Asp
AspAsp
Asp
 
AngularJs - Part 3
AngularJs - Part 3AngularJs - Part 3
AngularJs - Part 3
 
Building Templates for Joomla
Building Templates for JoomlaBuilding Templates for Joomla
Building Templates for Joomla
 
Css Founder.com | Cssfounder Org
Css Founder.com | Cssfounder OrgCss Founder.com | Cssfounder Org
Css Founder.com | Cssfounder Org
 
Bad Form @ JSConf Asia 2014
Bad Form @ JSConf Asia 2014Bad Form @ JSConf Asia 2014
Bad Form @ JSConf Asia 2014
 
Ddpz2613 topic6 frame
Ddpz2613 topic6 frameDdpz2613 topic6 frame
Ddpz2613 topic6 frame
 
Element Styles and Positioning
Element Styles and PositioningElement Styles and Positioning
Element Styles and Positioning
 
PHP Forms PHP 05
PHP Forms PHP 05PHP Forms PHP 05
PHP Forms PHP 05
 
Rounded Shaped Box Example 1
Rounded Shaped Box Example 1Rounded Shaped Box Example 1
Rounded Shaped Box Example 1
 
Java script functions
Java script   functionsJava script   functions
Java script functions
 
Drupal Cafe №5 Харьков. Drupal 7 Views 3.
Drupal Cafe №5 Харьков. Drupal 7 Views 3.Drupal Cafe №5 Харьков. Drupal 7 Views 3.
Drupal Cafe №5 Харьков. Drupal 7 Views 3.
 
Javascript
JavascriptJavascript
Javascript
 

Viewers also liked

Build Apps
Build AppsBuild Apps
Build Apps
Victor Miclovich
 
Okfest
OkfestOkfest
Mobile communities and innovation
Mobile communities and innovationMobile communities and innovation
Mobile communities and innovation
Victor Miclovich
 
Crowdmapping
CrowdmappingCrowdmapping
Crowdmapping
Victor Miclovich
 
Story spaces pitch
Story spaces pitchStory spaces pitch
Story spaces pitch
Victor Miclovich
 
Android Development Slides
Android Development SlidesAndroid Development Slides
Android Development Slides
Victor Miclovich
 
Google devfest makerere university
Google devfest makerere universityGoogle devfest makerere university
Google devfest makerere university
Victor Miclovich
 

Viewers also liked (7)

Build Apps
Build AppsBuild Apps
Build Apps
 
Okfest
OkfestOkfest
Okfest
 
Mobile communities and innovation
Mobile communities and innovationMobile communities and innovation
Mobile communities and innovation
 
Crowdmapping
CrowdmappingCrowdmapping
Crowdmapping
 
Story spaces pitch
Story spaces pitchStory spaces pitch
Story spaces pitch
 
Android Development Slides
Android Development SlidesAndroid Development Slides
Android Development Slides
 
Google devfest makerere university
Google devfest makerere universityGoogle devfest makerere university
Google devfest makerere university
 

Similar to Django Girls Mbale [victor's sessions]

Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
Joaquim Rocha
 
Django workshop : let's make a blog
Django workshop : let's make a blogDjango workshop : let's make a blog
Django workshop : let's make a blog
Pierre Sudron
 
Practical HTML5: Using It Today
Practical HTML5: Using It TodayPractical HTML5: Using It Today
Practical HTML5: Using It Today
Doris Chen
 
Django Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, TricksDjango Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, Tricks
Shawn Rider
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
fishwarter
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
fishwarter
 
The go-start webframework (GTUG Vienna 27.03.2012)
The go-start webframework (GTUG Vienna 27.03.2012)The go-start webframework (GTUG Vienna 27.03.2012)
The go-start webframework (GTUG Vienna 27.03.2012)
ungerik
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
fishwarter
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
fishwarter
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress Websites
Kyle Cearley
 
MVC and Razor - Doc. v1.2
MVC and Razor - Doc. v1.2MVC and Razor - Doc. v1.2
MVC and Razor - Doc. v1.2
Naji El Kotob
 
Joomla Beginner Template Presentation
Joomla Beginner Template PresentationJoomla Beginner Template Presentation
Joomla Beginner Template Presentation
alledia
 
Javascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksJavascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & Tricks
Hjörtur Hilmarsson
 
Django Vs Rails
Django Vs RailsDjango Vs Rails
Django Vs Rails
Sérgio Santos
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django Introduction
Ganga Ram
 
Joomlapresentation
JoomlapresentationJoomlapresentation
Joomlapresentation
guestf44ffc
 
JoomlaEXPO Presentation by Joe LeBlanc
JoomlaEXPO Presentation by Joe LeBlancJoomlaEXPO Presentation by Joe LeBlanc
JoomlaEXPO Presentation by Joe LeBlanc
John Coonen
 
Joomlapresentation
JoomlapresentationJoomlapresentation
Joomlapresentation
jlleblanc
 
Discovering Django - zekeLabs
Discovering Django - zekeLabsDiscovering Django - zekeLabs
Discovering Django - zekeLabs
zekeLabs Technologies
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
Wade Austin
 

Similar to Django Girls Mbale [victor's sessions] (20)

Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Django workshop : let's make a blog
Django workshop : let's make a blogDjango workshop : let's make a blog
Django workshop : let's make a blog
 
Practical HTML5: Using It Today
Practical HTML5: Using It TodayPractical HTML5: Using It Today
Practical HTML5: Using It Today
 
Django Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, TricksDjango Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, Tricks
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
The go-start webframework (GTUG Vienna 27.03.2012)
The go-start webframework (GTUG Vienna 27.03.2012)The go-start webframework (GTUG Vienna 27.03.2012)
The go-start webframework (GTUG Vienna 27.03.2012)
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress Websites
 
MVC and Razor - Doc. v1.2
MVC and Razor - Doc. v1.2MVC and Razor - Doc. v1.2
MVC and Razor - Doc. v1.2
 
Joomla Beginner Template Presentation
Joomla Beginner Template PresentationJoomla Beginner Template Presentation
Joomla Beginner Template Presentation
 
Javascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksJavascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & Tricks
 
Django Vs Rails
Django Vs RailsDjango Vs Rails
Django Vs Rails
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django Introduction
 
Joomlapresentation
JoomlapresentationJoomlapresentation
Joomlapresentation
 
JoomlaEXPO Presentation by Joe LeBlanc
JoomlaEXPO Presentation by Joe LeBlancJoomlaEXPO Presentation by Joe LeBlanc
JoomlaEXPO Presentation by Joe LeBlanc
 
Joomlapresentation
JoomlapresentationJoomlapresentation
Joomlapresentation
 
Discovering Django - zekeLabs
Discovering Django - zekeLabsDiscovering Django - zekeLabs
Discovering Django - zekeLabs
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
 

Recently uploaded

spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
paigestewart1632
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 

Recently uploaded (20)

spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 

Django Girls Mbale [victor's sessions]

  • 6. views.py def some_view(request): return render_to_response(“path/to/template.html”, {}, RequestContext(request))
  • 7. HTML <html> <head> <title>Hello world</title> </head> <body> <p>Hi</p> </body> </html>
  • 8. Tags in HTML ● Paragraphs ● Headers ● Divs ● Section ● asection ● etc. ● See W3C tutorials and plenty of Online tutorials
  • 9. CSS (Cascading Style Sheets) `style.css` p{ color: red; }
  • 10. CSS (Cascading Style Sheets) `style.css` .food_section{ color: red; }
  • 11. CSS (Cascading Style Sheets) `style.css` #food_section{ color: red; }
  • 12. Bootstrap `http://getbootstrap.com` <head> <link rel=”styleshet” href=”path/to/bootstrap.css”> </head> <body> ...some code… <script src=”path/to/bootstrap.js”></script>
  • 13. Google Fonts `http://www.google.com/fonts` <head> <link rel=”styleshet” href=”path/to/bootstrap.css”> <link href='http://fonts.googleapis.com/css? family=Open+Sans' rel='stylesheet' type='text/css'> </head> <body>...</body>
  • 15. URLs.. Maps your “view functions” to a URL. ● someone visits a URL ● URL tells django what to do ● Django returns a set of HTML (templates)
  • 16. Templates [part 1] Just HTML… take it EASY!
  • 17. Templates mysite ⇒ mysite ===> templates/mysite ===> [other folders] ⇒ app1 ===> templates/app1 ===> [other folders] ⇒ app2 ===> templates/app2 ===> [other folders]
  • 18. forms [Non-model based] ● Create `forms.py` in your Django Application ● import the Form class ● define what you’ll collect
  • 19. forms [Non-model based] from django import forms class MessageForm(forms.Form): number = forms.CharField() text = forms.CharField()
  • 20. Hooking up forms in Views from form import MessageForm def new_message(request): form = MessageForm() if request.method == “POST”: form = MessageForm(request.POST) if form.valid(): form.save() # save else: pass # handle errors! return render_to_response(‘messages/new.html’, {‘form’:form}, RequestContext(request))
  • 22. forms [Model based] ● Create `forms.py` in your Django Application ● import the Form class ● define what you’ll collect
  • 23. forms [Model based] from django import forms from .models import Message class MessageForm(forms.ModelForm): model = Message
  • 24. Hooking up forms in Views (similar) from form import MessageForm def new_message(request): form = MessageForm() if request.method == “POST”: form = MessageForm(request.POST) if form.valid(): form.save() # save else: pass # handle errors! return render_to_response(‘messages/new.html’, {‘form’:form}, RequestContext(request))
  • 25. Hooking up forms in HTML <form
  • 27. Template inheritance Base HTML file e.g. base.html Profile page e.g. profile.html Messages page e.g. messages.html
  • 28. Template inheritance Base HTML file e.g. base.html Profile page e.g. profile.html Base HTML has your site-wide designs and you don’t have to repeat the design on different pages. Messages page e.g. messages.html
  • 29. Template inheritance Base HTML file e.g. base.html code sample... <html> <head> <!-- CSS or js here --> </head> <body> {% block content %} {% endblock %} </body> </html>
  • 30. Template inheritance {% extends “base.html” %} {% block content %} <div> Hi {{ name }}. You are seeing your profile. </div> {% endblock %} Profile page e.g. profiles.html code sample...
  • 32. ● Do the django girls tutorial ● Do the 6 part django tutorial (http: //djangoproject.com) ● Google a lot! ● Do many projects.. ● Check out TDD