A talk I gave at DJUGL in May of 2011
Andrew Godwinhttp://www.flickr.com/photos/caroslines/1371200717/What's new in Django 1.3?
View Slide
Hi, I'm Andrew.Serial Python developerDjango core committerCo-founder of ep.io(Python hosting platform)
Django: A Very Brief HistoryInitial release in 20051.0 released in 20081.3 released March 2011
1.3 was the "bugfix release"The plan: No major features, quick release
1.3 was the "bugfix release"The plan: No major features, quick releaseThe result: 2 major features, 10 months
1.3 was the "bugfix release"The plan: No major features, quick releaseThe result: 2 major features, 10 monthsWe'll get the next one out quicker...
New FeaturesClass-based viewsLoggingcontrib.staticfilesunitttest2on_deleteTemplateResponse
Notable ChangesCSRF on AJAX requestsLess swearwordsTranslation/i18n improvementsNo more mod_pythonNo more XMLFieldrender() shortcut
Class-Based ViewsBiggest change in 1.3Not required for all new viewsDesigned to simplify common patterns
CBV: Beforedef object_detail(request, year, month, day, queryset,date_field, month_format='%b',day_format='%d', object_id=None,slug=None, slug_field='slug',template_name=None,template_name_field=None,template_loader=loader,extra_context=None,context_processors=None,template_object_name='object',mimetype=None, allow_future=False):
CBV: Afterclass AccountDetail(DetailView):model = Accountcontext_object_name = "account"slug_field = "snail"def get_context_data(self, **kwargs):context = super(AccountDetail, self)\.get_context_data(**kwargs)context['books'] = Book.objects.all()return context
CBV: Simple views too!class AccountDetail(TemplateView):template_name = "mytempl.html"def get_context_data(self, **kwargs):return {"books": Book.objects.all(),"is_evil": True,}
Other usesRefactor common parts into superclassesMixins for adding-on functionalityMutate the input or output
LoggingNow actually sensible, not just emailsUses standard Python logging libraryConfigured using the LOGGING setting
LOGGING = {'version': 1,'disable_existing_loggers': True,'handlers': {'console':{'level': 'DEBUG','class': 'logging.StreamHandler',},'mail_admins': {'level': 'ERROR','class': 'django.utils.log.AdminEmailHandler',}},'loggers': {'django.request': {'handlers': ['mail_admins'],'level': 'ERROR',},'myproject.custom': {'handlers': ['console', 'mail_admins'],'level': 'INFO',}}}
staticfilesLets apps ship with their static filesView to serve them in development./manage.py collectstatic for production
unittest2Better than unittest (obviously)Many new assertion methodsTest skippingExpected failuresMuch more...
unittest2Bundled with DjangoJust change:import unittestfrom django.utils import unittestto
on_deleteDeleting rows just got better!Cascade delete (as before)Set to NULLRaise ProtectedErrorSet to arbitary value
TemplateResponseA HTTPResponse class you can changeTemplate only run at end of middlewareChange context, or even template
TemplateResponse Examplefrom django.template.response \import TemplateResponsedef blog_index(request):return TemplateResponse(request,'entry_list.html',{'entries': Entry.objects.all()},)...response.context_data['foo'] = 'bar'
CSRF on AJAX requestsCSRF is a hard, hard problemFlash plus 307 redirect = failYou'll have to start supplyingCSRF tokens to your JavaScript
Less SwearwordsGuaranteed, or your money back.Also gone: "asshat", "asshead".
Translation / i18nMarking for ambiguous meaningsOverrideable translations for appsDeprecation of project-wide translations
No more mod_pythonIt's dead, Jim.If you're still using it, move to mod_wsgior gunicorn now, please.
No more XMLFieldWe're not really sure why it was therein the first place.
render() shortcutLike render_to_response, but :Less characters to typeUses RequestContextHandy for those not on CBV
How do you upgrade?Should be mostly seamless.You'll get warnings for deprecated settings(e.g. DATABASE_NAME)
What's going to be in 1.4?We're not quite sure yet.Possible:App refactorHTML5 doctypeORM changes
Future featuresGSOC should give us:Template engine refactorNew form renderingSchema alteration low-level APIComposite fields
Thank you.Andrew Godwin@andrewgodwin[email protected]