SlideShare uma empresa Scribd logo
1 de 33
Unchain Your Web
Development with Django
The web framework for perfectionists with deadlines.
Who am I?
● Started using Python 1.5.2 in 1998
● Started using Django 0.96 in 2008
● Contributing to open source projects since ~2000
● @mrbeersnob
● github.com/tarkatronic
What is Django?
No, really, what is it?
The web framework for professionals with deadlines
● Originally built for the Lawrence Journal-World newspaper in 2003
● A bundled collection of tools to build powerful web applications quickly
● Focused on automation and DRY
Who actually uses this thing?
● Disqus
● Instagram
● Pinterest
● Washington Post
● National Geographic
● Many, many more…
● https://www.djangosites.org/
Why should I use it?
● ORM
● Caching
● Internationalization
● Class-based views!
● Templating
● Automatically generated admin interface
● Database migrations
● Built-in management commands
Django doesn’t provide ____. Do I have to build it?
● Social authentication? django-allauth
● REST API? django-rest-framework
● Two factor authentication? django-two-factor-auth
● CMS? wagtail, django-cms, etc
● https://www.djangopackages.com/
● https://djangosnippets.org/
Let’s get started!
Setting things up
● pip install Django
● django-admin.py startproject cocktails
● …
● Profit!
Okay, maybe a little more than that.
./manage.py runserver
…
Starting development server at http://127.0.0.1:8000/
Creating an application
django-admin.py startapp recipes
recipes/
migrations/
__init__.py
__init__.py
admin.py
models.py
tests.py
views.py
settings.py:
INSTALLED_APPS = (
…
'cocktails.recipes'
)
First step: Models
from django.db import models
class Ingredient(models.Model):
OUNCE = 'ounce'
TEASPOON = 'tsp'
TABLESPOON = 'tbsp'
DASH = 'dash'
MEASUREMENTS = (
(OUNCE, 'Ounce(s)'),
(TEASPOON, 'Teaspoon(s)'),
(TABLESPOON, 'Tablespoon(s)'),
(DASH, 'Dash(es)'),
)
name = models.CharField(max_length=255)
measurement = models.CharField(max_length=5, choices=MEASUREMENTS, null=True, blank=True)
def __str__(self):
return self.name
A couple more...
class Drink(models.Model):
name = models.CharField(max_length=255)
components = models.ManyToManyField('Ingredient', through='Component', related_name='drinks')
def __str__(self):
return self.name
class Component(models.Model):
drink = models.ForeignKey('recipes.Drink', related_name='+')
ingredient = models.ForeignKey('recipes.Ingredient', related_name='+')
amount = models.FloatField()
def __str__(self):
return '%s %s %s (%s)' % (self.ingredient.name, self.amount,
self.ingredient.get_measurement_display() or '', self.drink.name)
One more piece
class Step(models.Model):
drink = models.ForeignKey('Drink', related_name='steps')
text = models.TextField()
class Meta:
order_with_respect_to = 'drink'
def __str__(self):
return '%s step #%s' % (self.drink.name, self._order + 1)
Time to set up the database...
CREATE DATABASE;
CREATE TABLE …;
...right?
Nope! Migrations to the rescue.
./manage.py makemigrations
Migrations for 'recipes':
0001_initial.py:
- Create model Component
- Create model Drink
- Create model Ingredient
- Create model Step
- Add field components to drink
- Add field drink to component
- Add field ingredient to component
- Set order_with_respect_to on step to drink
./manage.py migrate
Operations to perform:
Synchronize unmigrated apps: staticfiles, messages
Apply all migrations: admin, contenttypes, recipes, auth, sessions
… lots more words …
Done!
About that admin interface...
admin.py:
from django.contrib import admin
from .models import Component, Drink, Ingredient, Step
class ComponentInline(admin.TabularInline):
model = Component
class StepInline(admin.StackedInline):
model = Step
class DrinkAdmin(admin.ModelAdmin):
inlines = [ComponentInline, StepInline]
admin.site.register(Component)
admin.site.register(Drink)
admin.site.register(Ingredient)
admin.site.register(Step)
Creating an admin user
Another built-in management command!
./manage.py createsuperuser
Username (leave blank to use 'jwilhelm'):
Email address: jwilhelm@opay.io
Password:
Password (again):
Superuser created successfully.
Log in, and like magic, we get...
Adding some records
Our inlines at work
Making things visible: views
views.py:
from django.core.urlresolvers import reverse_lazy
from django.views.generic import DetailView, ListView
from .models import Component, Drink
class DrinkListView(ListView):
model = Drink
class DrinkDetailView(DetailView):
model = Drink
def get_context_data(self, **kwargs):
context = super(DrinkDetailView, self).get_context_data(**kwargs)
context.update({'components': Component.objects.filter(drink=self.get_object())})
return context
Pulling it together with a couple templates
base.html:
<html>
<head>
<title>Cocktail Database</title>
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>
List all the things!
recipes/drink_list.html:
{% extends "base.html" %}
{% block content %}
{% for drink in object_list %}
{% if forloop.first %}
<ul>
{% endif %}
<li><a href="{% url 'drink_detail' drink.id %}">{{ drink.name }}</a></li>
{% if forloop.last %}
</ul>
{% endif %}
{% empty %}
No drinks yet in the database.
{% endfor %}
{% endblock %}
It's all in the details
recipes/drink_detail.html:
{% extends "base.html" %}
{% block content %}
<h1>{{ drink.name }}</h1>
<dl>
<dt>Ingredients</dt>
<dd>
<ul>
{% for component in components %}
<li>{{ component.amount }}{% if component.ingredient.measurement %} {{
component.ingredient.measurement }}{% endif %} {{ component.ingredient.name }}</li>
{% endfor %}
</ul>
</dd>
...
Details, continued
...
<td>Steps</td>
<dd>
<ol>
{% for step in drink.steps.all %}
<li>{{ step.text }}</li>
{% endfor %}
</ol>
</dd>
</dl>
{% endblock %}
Just one more piece: urls
urls.py:
from cocktails.recipes.views import DrinkDetailView, DrinkListView
urlpatterns = [
...
url(r'^drinks/$', DrinkListView.as_view(), name='drink_list'),
url(r'^drinks/(?P<pk>[0-9]+)/$', DrinkDetailView.as_view(), name='drink_detail'),
]
The (ugly, ugly) fruits of our labor
The (slightly less ugly) details
The full code, plus a bit more
django-cocktails repository: https://github.com/tarkatronic/django-cocktails
What if I need help?
“I came for the auto generated admin, but I stayed for the community.”
-Ola Sitarska
● StackOverflow - http://stackoverflow.com/questions/tagged/django
● django-users mailing list - https://groups.google.com/forum/#!forum/django-
users
● IRC: #django on Freenode (I'm often on as TheJoey)
Now, go learn more!
Django Project website: http://www.djangoproject.com/
Django Girls tutorial: http://tutorial.djangogirls.org/
Getting Started with Django: http://gettingstartedwithdjango.com/
Two Scoops of Django: http://twoscoopspress.org/
Cheers!

Mais conteúdo relacionado

Mais procurados

jQuery
jQueryjQuery
jQuery
i.omar
 
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
SPTechCon
 
Djangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django applicationDjangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django application
Masashi Shibata
 

Mais procurados (20)

The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)
 
jQuery
jQueryjQuery
jQuery
 
What's new in Rails 4
What's new in Rails 4What's new in Rails 4
What's new in Rails 4
 
Cheap tricks for startups
Cheap tricks for startupsCheap tricks for startups
Cheap tricks for startups
 
Enough with the javas cript already! de Nicholas Zakas
Enough with the javas cript already! de Nicholas ZakasEnough with the javas cript already! de Nicholas Zakas
Enough with the javas cript already! de Nicholas Zakas
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
 
JavaServer Pages
JavaServer Pages JavaServer Pages
JavaServer Pages
 
Django
DjangoDjango
Django
 
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
 
Django の認証処理実装パターン / Django Authentication Patterns
Django の認証処理実装パターン / Django Authentication PatternsDjango の認証処理実装パターン / Django Authentication Patterns
Django の認証処理実装パターン / Django Authentication Patterns
 
An Overview of Models in Django
An Overview of Models in DjangoAn Overview of Models in Django
An Overview of Models in Django
 
Asp.net By Durgesh Singh
Asp.net By Durgesh SinghAsp.net By Durgesh Singh
Asp.net By Durgesh Singh
 
Advanced JQuery Mobile tutorial with Phonegap
Advanced JQuery Mobile tutorial with Phonegap Advanced JQuery Mobile tutorial with Phonegap
Advanced JQuery Mobile tutorial with Phonegap
 
jQuery For Developers Stack Overflow Dev Days Toronto
jQuery For Developers Stack Overflow Dev Days TorontojQuery For Developers Stack Overflow Dev Days Toronto
jQuery For Developers Stack Overflow Dev Days Toronto
 
jQuery Mobile with HTML5
jQuery Mobile with HTML5jQuery Mobile with HTML5
jQuery Mobile with HTML5
 
4. jsp
4. jsp4. jsp
4. jsp
 
Watir web automated tests
Watir web automated testsWatir web automated tests
Watir web automated tests
 
SwiftUI and Combine All the Things
SwiftUI and Combine All the ThingsSwiftUI and Combine All the Things
SwiftUI and Combine All the Things
 
Desbravando Web Components
Desbravando Web ComponentsDesbravando Web Components
Desbravando Web Components
 
Djangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django applicationDjangoアプリのデプロイに関するプラクティス / Deploy django application
Djangoアプリのデプロイに関するプラクティス / Deploy django application
 

Semelhante a Unchain Your Web Development With Django

django_introduction20141030
django_introduction20141030django_introduction20141030
django_introduction20141030
Kevin Wu
 
Templates
TemplatesTemplates
Templates
soon
 

Semelhante a Unchain Your Web Development With Django (20)

Django crush course
Django crush course Django crush course
Django crush course
 
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 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
 
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
 
PHPConf-TW 2012 # Twig
PHPConf-TW 2012 # TwigPHPConf-TW 2012 # Twig
PHPConf-TW 2012 # Twig
 
Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!
 
Django Vs Rails
Django Vs RailsDjango Vs Rails
Django Vs Rails
 
Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4
 
django_introduction20141030
django_introduction20141030django_introduction20141030
django_introduction20141030
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Templates
TemplatesTemplates
Templates
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Rails Antipatterns | Open Session with Chad Pytel
Rails Antipatterns | Open Session with Chad Pytel Rails Antipatterns | Open Session with Chad Pytel
Rails Antipatterns | Open Session with Chad Pytel
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 

Unchain Your Web Development With Django

  • 1. Unchain Your Web Development with Django The web framework for perfectionists with deadlines.
  • 2. Who am I? ● Started using Python 1.5.2 in 1998 ● Started using Django 0.96 in 2008 ● Contributing to open source projects since ~2000 ● @mrbeersnob ● github.com/tarkatronic
  • 4. No, really, what is it? The web framework for professionals with deadlines ● Originally built for the Lawrence Journal-World newspaper in 2003 ● A bundled collection of tools to build powerful web applications quickly ● Focused on automation and DRY
  • 5. Who actually uses this thing? ● Disqus ● Instagram ● Pinterest ● Washington Post ● National Geographic ● Many, many more… ● https://www.djangosites.org/
  • 6. Why should I use it? ● ORM ● Caching ● Internationalization ● Class-based views! ● Templating ● Automatically generated admin interface ● Database migrations ● Built-in management commands
  • 7. Django doesn’t provide ____. Do I have to build it? ● Social authentication? django-allauth ● REST API? django-rest-framework ● Two factor authentication? django-two-factor-auth ● CMS? wagtail, django-cms, etc ● https://www.djangopackages.com/ ● https://djangosnippets.org/
  • 9. Setting things up ● pip install Django ● django-admin.py startproject cocktails ● … ● Profit!
  • 10. Okay, maybe a little more than that. ./manage.py runserver … Starting development server at http://127.0.0.1:8000/
  • 11. Creating an application django-admin.py startapp recipes recipes/ migrations/ __init__.py __init__.py admin.py models.py tests.py views.py settings.py: INSTALLED_APPS = ( … 'cocktails.recipes' )
  • 12. First step: Models from django.db import models class Ingredient(models.Model): OUNCE = 'ounce' TEASPOON = 'tsp' TABLESPOON = 'tbsp' DASH = 'dash' MEASUREMENTS = ( (OUNCE, 'Ounce(s)'), (TEASPOON, 'Teaspoon(s)'), (TABLESPOON, 'Tablespoon(s)'), (DASH, 'Dash(es)'), ) name = models.CharField(max_length=255) measurement = models.CharField(max_length=5, choices=MEASUREMENTS, null=True, blank=True) def __str__(self): return self.name
  • 13. A couple more... class Drink(models.Model): name = models.CharField(max_length=255) components = models.ManyToManyField('Ingredient', through='Component', related_name='drinks') def __str__(self): return self.name class Component(models.Model): drink = models.ForeignKey('recipes.Drink', related_name='+') ingredient = models.ForeignKey('recipes.Ingredient', related_name='+') amount = models.FloatField() def __str__(self): return '%s %s %s (%s)' % (self.ingredient.name, self.amount, self.ingredient.get_measurement_display() or '', self.drink.name)
  • 14. One more piece class Step(models.Model): drink = models.ForeignKey('Drink', related_name='steps') text = models.TextField() class Meta: order_with_respect_to = 'drink' def __str__(self): return '%s step #%s' % (self.drink.name, self._order + 1)
  • 15. Time to set up the database... CREATE DATABASE; CREATE TABLE …; ...right?
  • 16. Nope! Migrations to the rescue. ./manage.py makemigrations Migrations for 'recipes': 0001_initial.py: - Create model Component - Create model Drink - Create model Ingredient - Create model Step - Add field components to drink - Add field drink to component - Add field ingredient to component - Set order_with_respect_to on step to drink ./manage.py migrate Operations to perform: Synchronize unmigrated apps: staticfiles, messages Apply all migrations: admin, contenttypes, recipes, auth, sessions … lots more words … Done!
  • 17. About that admin interface... admin.py: from django.contrib import admin from .models import Component, Drink, Ingredient, Step class ComponentInline(admin.TabularInline): model = Component class StepInline(admin.StackedInline): model = Step class DrinkAdmin(admin.ModelAdmin): inlines = [ComponentInline, StepInline] admin.site.register(Component) admin.site.register(Drink) admin.site.register(Ingredient) admin.site.register(Step)
  • 18. Creating an admin user Another built-in management command! ./manage.py createsuperuser Username (leave blank to use 'jwilhelm'): Email address: jwilhelm@opay.io Password: Password (again): Superuser created successfully.
  • 19. Log in, and like magic, we get...
  • 22. Making things visible: views views.py: from django.core.urlresolvers import reverse_lazy from django.views.generic import DetailView, ListView from .models import Component, Drink class DrinkListView(ListView): model = Drink class DrinkDetailView(DetailView): model = Drink def get_context_data(self, **kwargs): context = super(DrinkDetailView, self).get_context_data(**kwargs) context.update({'components': Component.objects.filter(drink=self.get_object())}) return context
  • 23. Pulling it together with a couple templates base.html: <html> <head> <title>Cocktail Database</title> </head> <body> {% block content %}{% endblock %} </body> </html>
  • 24. List all the things! recipes/drink_list.html: {% extends "base.html" %} {% block content %} {% for drink in object_list %} {% if forloop.first %} <ul> {% endif %} <li><a href="{% url 'drink_detail' drink.id %}">{{ drink.name }}</a></li> {% if forloop.last %} </ul> {% endif %} {% empty %} No drinks yet in the database. {% endfor %} {% endblock %}
  • 25. It's all in the details recipes/drink_detail.html: {% extends "base.html" %} {% block content %} <h1>{{ drink.name }}</h1> <dl> <dt>Ingredients</dt> <dd> <ul> {% for component in components %} <li>{{ component.amount }}{% if component.ingredient.measurement %} {{ component.ingredient.measurement }}{% endif %} {{ component.ingredient.name }}</li> {% endfor %} </ul> </dd> ...
  • 26. Details, continued ... <td>Steps</td> <dd> <ol> {% for step in drink.steps.all %} <li>{{ step.text }}</li> {% endfor %} </ol> </dd> </dl> {% endblock %}
  • 27. Just one more piece: urls urls.py: from cocktails.recipes.views import DrinkDetailView, DrinkListView urlpatterns = [ ... url(r'^drinks/$', DrinkListView.as_view(), name='drink_list'), url(r'^drinks/(?P<pk>[0-9]+)/$', DrinkDetailView.as_view(), name='drink_detail'), ]
  • 28. The (ugly, ugly) fruits of our labor
  • 29. The (slightly less ugly) details
  • 30. The full code, plus a bit more django-cocktails repository: https://github.com/tarkatronic/django-cocktails
  • 31. What if I need help? “I came for the auto generated admin, but I stayed for the community.” -Ola Sitarska ● StackOverflow - http://stackoverflow.com/questions/tagged/django ● django-users mailing list - https://groups.google.com/forum/#!forum/django- users ● IRC: #django on Freenode (I'm often on as TheJoey)
  • 32. Now, go learn more! Django Project website: http://www.djangoproject.com/ Django Girls tutorial: http://tutorial.djangogirls.org/ Getting Started with Django: http://gettingstartedwithdjango.com/ Two Scoops of Django: http://twoscoopspress.org/