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
600
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
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
300
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
450
これって Effect でできたのでは? / TSKaigi Mashup Kansai #2
susisu
0
150
「人を評価する AI」の設計と実装
ryoyanara
0
180
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
540
the container ship “Apple Silicon”@WWDC26 Recap -Japan-\(region).swift
shingangan
0
110
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
200
複数の Claude Code が"放置"されてしまう問題をCLI ダッシュボードを自作して解決した話
sumihiro3
1
670
Go言語とトイモデルで学ぶTransformerの気持ち / fukuokago23-transformer
monochromegane
0
160
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
4
1.6k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
550
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
180
Featured
See All Featured
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
690
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
240
We Have a Design System, Now What?
morganepeng
55
8.3k
Six Lessons from altMBA
skipperchong
29
4.4k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
2
3.7k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.7k
Skip the Path - Find Your Career Trail
mkilby
1
180
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.7k
Making the Leap to Tech Lead
cromwellryan
135
10k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
310
Writing Fast Ruby
sferik
630
63k
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