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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Bruno Renié
April 03, 2012
Programming
450
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
580
Other Decks in Programming
See All in Programming
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
9
5.4k
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.4k
エージェンティックRAGにAWSで入門しよう!
har1101
8
1.6k
Webフレームワークの ベンチマークについて
yusukebe
0
170
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
160
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
790
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
240
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
510
dRuby over BLE
makicamel
2
340
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
200
Oxcを導入して開発体験が向上した話
yug1224
4
310
Vite+ Unified Toolchain for the Web
naokihaba
0
310
Featured
See All Featured
Technical Leadership for Architectural Decision Making
baasie
3
410
[SF Ruby Conf 2025] Rails X
palkan
2
1.1k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.2k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
590
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.5k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
530
The Cult of Friendly URLs
andyhume
79
6.9k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.5k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Amusing Abliteration
ianozsvald
1
200
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
240
ラッコキーワード サービス紹介資料
rakko
1
3.7M
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