Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Introduction to Django
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Bruno Renié
April 03, 2012
Programming
460
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Introduction to Django
Bruno Renié
April 03, 2012
More Decks by Bruno Renié
See All by Bruno Renié
Visibility for web developers
brutasse
3
480
Decentralization & real-time with PubSubHubbub
brutasse
1
190
Deployability of Python Web Applications
brutasse
17
2.4k
Stop writing settings files
brutasse
21
2.6k
Class-based Views: patterns and anti-patterns
brutasse
9
1.7k
Packager son projet Django
brutasse
4
590
Staticfiles : tout ce qu'il faut savoir, rien que ce qu'il faut savoir
brutasse
4
590
Other Decks in Programming
See All in Programming
才能?センス?知らん、 続けたもん勝ちだ。-- 結婚・出産・癌を越えてなお、私がプロダクトを創り続ける理由
16bitidol
2
830
トークンをケチるな、設計しろ:GitHub Copilotを賢く使うコンテキスト戦略
ochtum
0
310
フィードバックで育てるAI開発
kotaminato
1
110
コーディングルールの鮮度を保ちたい for SRE NEXT 2026 / keep-fresh-go-internal-conventions-sre-next-2026
handlename
0
140
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
170
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
340
【やさしく解説 設計編 #1】「ドメイン駆動」と「実装駆動」ってなに? 〜設計の考え方を、たとえ話で学ぼう〜
panda728
PRO
1
110
信頼性について考えてみる(SRE NEXT 2026 miniLT)
hayama17
0
140
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
3
790
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
270
1B+ /day規模のログを管理する技術
broadleaf
0
130
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
130
Featured
See All Featured
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
220
WCS-LA-2024
lcolladotor
0
680
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
Documentation Writing (for coders)
carmenintech
77
5.4k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
2
320
Building Adaptive Systems
keathley
44
3.1k
From π to Pie charts
rasagy
0
230
New Earth Scene 8
popppiees
3
2.4k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
190
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
Transcript
Django Webmardi - 03.04.2012 @brutasse
$ whoami
“Django is a high-level Python Web framework that encourages rapid
development and clean, pragmatic design”
None
None
Théorie
Real-world app: Cheese catalog Like / dislike cheeses Twitter authentication
$ pip install Django http://www.pip-installer.org
$ django-admin.py startproject webmardi webmardi/ ├── manage.py └── webmardi ├──
__init__.py ├── settings.py ├── urls.py └── wsgi.py
manage.py Project toolbox
$ python manage.py startpapp cheese cheese/ ├── __init__.py ├── models.py
├── tests.py └── views.py
Models ORM
from django.db import models from ..users.models import User class Cheese(models.Model):
name = models.CharField(max_length=255) image = models.ImageField(upload_to='cheese') description = models.TextField() class Taste(models.Model): cheese = models.ForeignKey(Cheese, related_name='tastes') user = models.ForeignKey(User) like = models.BooleanField(default=True) class Meta: unique_together = ('cheese', 'user')
Admin Customizable edition interface
from django.contrib import admin from .models import Cheese, Taste class
CheeseAdmin(admin.ModelAdmin): list_display = ('name', 'image') class TasteAdmin(admin.ModelAdmin): list_display = ('cheese', 'user', 'like') admin.site.register(Cheese, CheeseAdmin) admin.site.register(Taste, TasteAdmin)
Views Request handling
from django.template.response import TemplateResponse from .models import Cheese, Taste def
cheese_list(request): context = { 'cheeses': Cheese.objects.all(), } return TemplateResponse(request, 'cheese_list.html', context)
URLs HTTP routing
from django.conf.urls import patterns, url from . import views urlpatterns
= patterns('', url(r'^$', views.cheese_list, name='cheese_list'), url(r'^cheese/(?P<pk>\d+)/$', views.cheese_detail, name='cheese_detail'), url(r'^cheese/(?P<pk>\d+)/like/$', views.like_cheese, name='like_cheese'), url(r'^cheese/(?P<pk>\d+)/dislike/$', views.dislike_cheese, name='dislike_cheese'), url(r'^cheese/add/$', views.add_cheese, name='add_cheese'), )
Templates
<!-- base.html --> <html> <head> <title>{% block title %}{% endblock
%}</title> </head> <body> {% block content %}{% endblock %} </body> </html>
<!-- cheese_list.html --> {% extends "base.html" %} {% load thumbnail
markup %} {% block title %}Cheese types{% endblock %} {% block content %} {% for cheese in cheeses %} <h2>{{ cheese.name }}</h2> <img src="{% thumbnail cheese.image 300x300 crop %}"> {{ cheese.description|markdown }} {% endfor %} {% endblock %}
Tests Untested code is by definition broken
from django.core.urlresolvers import reverse from django.test import TestCase class CheeseTest(TestCase):
def test_home(self): url = reverse('cheese_list') response = self.client.get(url) self.assertContains(response, 'Cheese')
Forms Input validation / sanitization <form> rendering
from django import forms from .models import Cheese class CheeseForm(forms.ModelForm):
class Meta: model = Cheese
GIS Cryptographic signing Browser testing i18n Flash messages Atom/RSS Email
Cache Storage Logging Unicode Comments
Search Error reporting HTML5 forms Database migrations CMS REST API
Background tasks Debugging There's an app for that
Questions‽ Thanks @liip Code: https://github.com/brutasse/webmardi Slides: http://speakerdeck.com/u/brutasse