I run Django San Diego and help run the San Diego Web Standards Group.
Couldn’t find a picture of your mascot
Don’t let Bryan Veloso unilaterally decide on your mascot.
Merb | Django |
---|---|
app | project |
slice | app |
controller | view |
view | template |
Merb team studied Django and other web frameworks
Slices are awesome—embrace them!
This is your gateway to reusability
heaven.
Separate slices for
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!
import
this
Explicit is better than implicit.
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.
</slices>
urls.py
looks more like this in the
futureGeneric 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),
)
This is pretty much the awesomest thing ever…
but it’s thoroughly tied to particular ORM.
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”
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}),)
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]
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.
Crucial to community growth