SlideShare une entreprise Scribd logo
1  sur  32
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

Css Founder.com | Cssfounder Org
Css Founder.com | Cssfounder OrgCss Founder.com | Cssfounder Org
Css Founder.com | Cssfounder OrgCss Founder
 
Bad Form @ JSConf Asia 2014
Bad Form @ JSConf Asia 2014Bad Form @ JSConf Asia 2014
Bad Form @ JSConf Asia 2014cliener
 
Element Styles and Positioning
Element Styles and PositioningElement Styles and Positioning
Element Styles and Positioningalexisabril
 
PHP Forms PHP 05
PHP Forms PHP 05PHP Forms PHP 05
PHP Forms PHP 05Spy Seat
 
Rounded Shaped Box Example 1
Rounded Shaped Box Example 1Rounded Shaped Box Example 1
Rounded Shaped Box Example 1Sibananda Panda
 
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
 

Tendances (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
 

En vedette (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
 

Similaire à Django Girls Mbale [victor's sessions]

Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJoaquim 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 blogPierre Sudron
 
Practical HTML5: Using It Today
Practical HTML5: Using It TodayPractical HTML5: Using It Today
Practical HTML5: Using It TodayDoris Chen
 
Django Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, TricksDjango Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, TricksShawn Rider
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2fishwarter
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2fishwarter
 
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 2fishwarter
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2fishwarter
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress WebsitesKyle Cearley
 
MVC and Razor - Doc. v1.2
MVC and Razor - Doc. v1.2MVC and Razor - Doc. v1.2
MVC and Razor - Doc. v1.2Naji El Kotob
 
Joomla Beginner Template Presentation
Joomla Beginner Template PresentationJoomla Beginner Template Presentation
Joomla Beginner Template Presentationalledia
 
Javascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksJavascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksHjörtur Hilmarsson
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django IntroductionGanga Ram
 
JoomlaEXPO Presentation by Joe LeBlanc
JoomlaEXPO Presentation by Joe LeBlancJoomlaEXPO Presentation by Joe LeBlanc
JoomlaEXPO Presentation by Joe LeBlancJohn Coonen
 
Joomlapresentation
JoomlapresentationJoomlapresentation
Joomlapresentationjlleblanc
 
Joomlapresentation
JoomlapresentationJoomlapresentation
Joomlapresentationguestf44ffc
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction DjangoWade Austin
 

Similaire à 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
 
JoomlaEXPO Presentation by Joe LeBlanc
JoomlaEXPO Presentation by Joe LeBlancJoomlaEXPO Presentation by Joe LeBlanc
JoomlaEXPO Presentation by Joe LeBlanc
 
Joomlapresentation
JoomlapresentationJoomlapresentation
Joomlapresentation
 
Joomlapresentation
JoomlapresentationJoomlapresentation
Joomlapresentation
 
Discovering Django - zekeLabs
Discovering Django - zekeLabsDiscovering Django - zekeLabs
Discovering Django - zekeLabs
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
 

Dernier

How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 

Dernier (20)

How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 

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