eat some code

Recommended Django libraries

My top 5 Django libraries

March 2016 #libraries  #top  #Django  #recommendations 

My two favorite things about Django are Python and the quality of the plugins (which reflects on the quality of Django itself and its community). Here is my personal top 5 of the most useful Django libraries.

I haven't included Django admin as it's already part of Django "core".

1.Django Debug Toolbar

The Django Debug Toolbar gives you plenty of information during development. I mainly use it to check the generated SQL queries and how long they are taking. In my opinion, that plugin deserves to be part of Django (within the contrib module). I have never worked on a Django application that didn't include it !

2.Factory Boy

Factory Boy is a library to build and create Model subclasses instances. This is useful for automated tests and for fixtures. For example if you have an Article model with 10 required fields, you could simply do this in a test:

class MyTest(...):

    def test_article_update():
         article = ArticleFactory.create(title="The title")
         # do something meant to update the article title
         self.assertEquals(article.title, "Updated title")

The factories let you specify the necessary information (the title in this case) without having to specify the values of all the required fields.

3.WebTest

django-webtest allows you to use WebTest in your tests. WebTest offers the perfect level of abstraction for functional tests *. "The tests WebTest runs are entirely equivalent to how a WSGI HTTP server would call an application." In other words, with django-webtest, you specify who the user is and what he does instead of calling GET and POST requests. It's a lot more natural and it tests your HTML too. Using WebTest allows to test the full stack (except Javascript interaction) without compromising the test-suit speed.

* unless you want to test javascript-heavy application. In that case, you should probably use Selenium.

I find WebTest extremely useful to test forms and different behaviours depending on the logged-in user.

4.Django suit

django-suit makes your admin looks nice and offer a few interesting features such as ordering. It takes 5 minutes to try it out; come on, give it a go.

5.FeinCMS

FeinCMS applies the "less is more" principle to its extreme. FeinCMS is a CMS that does nothing when you install it. It's a CMS framework and it's awesome. As a matter of fact, this very blog is built with FeinCMS.

With FeinCMS you create your customised blocks of content model called "content types" and specify what they are made of and where they can be used. For example, this article is made of RichText, Code and Image blocks. The Image content type has one field for the image and one for the alternative text. I could add an author field to the Image content type, make it a foreign key, a URL or anything I fancy really.

The flexibility of FeinCMS means that you can use it within any application where you need to give users the possibility to add blocks of content (and not just a predefined set of image and rich text fields).

Image Credits

Hero picture, race - by Paul Chessare via Free Images