Who am I?
- web app developer here in San Diego
- FreeBSD, PostgreSQL, mod_wsgi, Django, jQuery
- greybeard lisper at heart
- total Emacs junkie
Dorky things I do with my nerdy friends
I run Django San Diego and help run the San Diego Web Standards Group.
Merb and Django
What’s a merbivore anyway?
Couldn’t find a picture of your mascot

Learning from Django: Lesson #1
Don’t let Bryan Veloso unilaterally decide on your mascot.
Terminology
Merb | Django |
---|---|
app | project |
slice | app |
controller | view |
view | template |
Merb and Django
AWESOME!
Lots in common
Merb team studied Django and other web frameworks
- modularity
- pluggability
- clean
- obvious
- 1.0 is serious business
Topics
- Slices & modularity
- Admin interface
- Generic views
- Syndication
- Local flavors
- Documentation
- Agnosticism & defaults
Merb Slices / Django Apps
Slices are awesome—embrace them!
This is your gateway to reusability
heaven.
James Bennett's fourfold path (part 1)
- Do one thing, do it well
- Don't be afraid of multiple
appsslices
Unix Philosophy
- do one thing
- do it well
- work together
AWESOME!
Ex. MerbAuth
Separate slices for
- authentication
- user management
- role management
Site as glue
- each piece of functionality in separate slice
- Site stitches slices together in distinctive way
Profusion of many slices
Even simple Django sites easily end up composed of a dozen apps or more!
It’s hard
import
this
Namespaces are one honking great idea—let’s do more
of those!
The fourfold path, cont.
- Write for flexibility
Build to distributeslices are gems already!
Flexibility ≠ Monkeypatching
import
this
Explicit is better than implicit.
Protocol-Oriented Programming
Explicitly expose how your slice operates in a controlled manner, so that your slice continues to work when such exposed bits are changed out from under you.
Think aliasing vs. public API.
ObLisp: MetaObject Protocol
AWESOME!
Other examples
- MerbAuth’s strategies
- User signup slice + custom user profile workflow
Slice-centric Development
- slices as the core way to develop merb apps
</slices>
Your router pwns
- SRSLY
- I hope
urls.py
looks more like this in the future
Admin interface
Generic CRUD admin UI you get for free
# admin.py
from django.contrib import admin
from djangosd.apps.blog.models import Post
admin.site.register(Post)
# urls.py
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
('^admin/(.*)', admin.site.root),
)
Autoadmin cont.
This is pretty much the awesomest thing ever…
but it’s thoroughly tied to particular ORM.
Generic Views
from django.conf.urls.defaults import *
from djangosd.apps.blog.models import Post
info_dict = {
'queryset': Post.objects.all(),
'date_field': 'published',
}
# ...
# ...
urlpatterns =
patterns('django.views.generic.date_based',
(r'^(?P<year>\d{4})/(?P<slug>[-\w]+)/$',
'object_detail', info_dict),
(r'^(?P<year>\d{4})/$',
'archive_year', info_dict),
(r'^$', 'archive_index', info_dict),
)
N.B. “controller” vs. “view”
Syndication framework
from django.conf.urls.defaults import *
from djangosd.apps.blog.feeds \
import LatestPosts, LatestComments
feeds = {'posts': LatestPosts,
'comments': LatestComments,
}
urlpatterns = patterns('',
(r'^feeds/(?P<url>.*)/$',
'django.contrib.syndication.views.feed',
{'feed_dict': feeds}),)
Feed objects
from django.contrib.syndication.feeds import Feed
from blog.models import Post
class LatestPosts(Feed):
title = "Blah blah blah"
link = "/"
description = "Most recent posts blah."
def items(self):
return Post.objects.order_by('-published')[:10]
Local flavor
from django import forms
from django.contrib.localflavor.us.forms \
import USSocialSecurityNumberField
class SomeForm(forms.Form):
ssn = USSocialSecurityNumberField()
Also postal codes, phone numbers, region and city select boxes, etc.
Documentation
- two books in the pipeline: yay!
- new wiki: yay!
- RDoc ≠ documentation
Crucial to community growth
Agnosticism
- Merb ORM-agnostic
- (and template language-agnostic, and…)
Django’s branded defaults
- batteries included
- Where merb-stack is headed?
- e.g. jQuery, DataMapper, haml