DjangoCon 2015 lightning recap

Presenter Notes

Me (Romain Garrigues @rgarrigues)

Presenter Notes

Overall feeling

  • Focused on well being (and burnout/depression witness)
  • Friendly community (lot of first-time speakers)
  • Need to go outside (meet people, see real talks)

Presenter Notes

Architecture / Separating concerns

(@HannaKollo, @codeinthehole)

  • Avoid big files.
  • Use service layers to move business logic from views.


1 def my_view(request):
2     params = request.GET
3     # Lot of code here before returning HttpResponse
4     # ...
5     return HttpResponse("This is a too big view")

could be:

1 from import deal_with_data
3 def my_view(request):
4     params = request.GET
5     deal_with_data(params)
6     return HttpResponse("We have separated business from view logic")

Presenter Notes


(@magopian, @RaeKnowler)


  • Syntax more pythonic,
  • Interesting options (launch only last failed tests)
  • pytest-django: --reuse-db and --create-db

Added value compare to manage test:

  • verbatim output when test is failing, (dict assertion will give exact missing or excess element, instead of full dict)
  • hide all logging when test are passing by default
  • the console output is more readable and intuitive

Presenter Notes

Testing ... 2


Use randomised data and find edge cases for you

1 @given(floats())
2 def test_negation_is_self_inverse(x):
3     assert x == -(-x)

Presenter Notes

Django admin


  • Use for: small tricks to improve UI
  • Other themes: django-flat-theme, django-suit (commercial)
  • Don't use for: end-users UI, big customisations
  • Don't allow admin to do massive damage to website. (deleting critical entry, etc)

django admin dashboard with django-flat-theme

Presenter Notes


(@erikpub, @ubernostrum)

  • Test 12 basic security issues:
  • Examples of Django protections:
    • Timing attack on password
    • Sanity checks on choice field (can't give unexpected choice to server)
  • Check your package versions

Presenter Notes

Rabbit hole

(@asendecka, @thomaswturner)


  • Trying to resolve a problem that takes ages at the end
  • Hard to diagnose
  • Ask for help, do some breaks

Example (Django on Desktop)

Unbelievable stack (Django, C++, Firebird, CEF, Sikuli)

Presenter Notes

Performance issues


Big Three

  • Step 1: reduce SQL queries (select_related, prefetch_related on reverse FKey/M2M)
  • Step 2: do less work
    • move work out of request/response cycle (celery)
    • only fetch what you need (QuerySet.defer())
    • do calculations on the db (annotate, aggregate)
  • Step 3: caching (hard to invalidate, johnny-cache or django-cache-machine)


  • django-debug-toolbar
  • django-devserver

Presenter Notes



Swamp dragon

swampdragon architecture

Presenter Notes



  • Improving API for lookup, transforms, expressions

HStoreField (PostGreSQL, Django 1.8+)

1 class Dog(models.Model):
2     data = HStoreField()
4 Dog.objects.create(data={'breed': 'labrador', 'owner': 'Bob'})
5 Dog.objects.filter(data__breed='collie')

ArrayField (PostGreSQL, Django 1.8+)

1 class Post(models.Model):
2     tags = ArrayField(models.CharField(max_length=200), blank=True)
4 Post.objects.create(name='First post', tags=['thoughts', 'django', 'd'])
5 Post.objects.filter(tags__contains=['django', 'thoughts'])

Presenter Notes

Useful tools


Encrypt/decrypt files on GitHub

Initialise your repository:

git-crypt init

Create a .gitattributes file to encrypt (in this example) .key files

secretfile filter=git-crypt diff=git-crypt
*.key filter=git-crypt diff=git-crypt


Django project templating

CAMEL project

Convert LaTeX documents to data saved in database, and render it through Django.

Presenter Notes


  • Lend money to small/medium businesses,
  • Non middle-age technologies

iwoca architecture

Presenter Notes


  • REALLY friendly
  • Take care of yourself !!
  • Not so technical ->
  • Pies in pieminister and welsh cakes were ... waouh.
  • Presentation available @

Presenter Notes