Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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
470
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
490
Decentralization & real-time with PubSubHubbub
brutasse
1
200
Deployability of Python Web Applications
brutasse
17
2.4k
Stop writing settings files
brutasse
21
2.7k
Class-based Views: patterns and anti-patterns
brutasse
9
1.7k
Packager son projet Django
brutasse
4
610
Staticfiles : tout ce qu'il faut savoir, rien que ce qu'il faut savoir
brutasse
4
600
Other Decks in Programming
See All in Programming
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2k
SREの越境 / SRE Collaboration
y0hgi
2
300
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
740
dotNET_vulnclicker_intro.pdf
deka_morita
0
130
複雑なUIコンポーネントとの ⻑い付き合い⽅:波及するバグからテスト戦略を経て、安全な再設計へ
mixplace
0
260
なぜCTOを降りてFDEを選んだのか?〜なぜプロダクト企業がFDEで顧客の現場に踏み込むのか〜
gonta
1
170
CodeRabbitの効果検証と過ごしてみた3ヶ月
armondando
0
200
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.5k
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
130
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
21
21k
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
160
mrbgem 三角測量 開発
ogom
0
220
Featured
See All Featured
Faster Mobile Websites
deanohume
310
32k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
620
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
700
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
300
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
490
How to train your dragon (web standard)
notwaldorf
96
6.9k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
550
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.3k
Docker and Python
trallard
47
4.2k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
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