Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
3 Django apps for sending great e-mails
3 Django apps for debugging and sending HTML styled e-mails -
Controlling access: a Django permission apps comparison
There are many ways to handle permissions in a project. This post highlights the main differences and approaches taken by some popular Django third party apps to handle permissions. -
Database concurrency in Django the right way
When developing applications which have real-time requirements or other specific needs for running asynchronous tasks outside the web application, it is common to adopt a task queue such as Celery. This allows, for example, for the server to handle a request, start an asynchronous task responsible of doing some heavyweight processing, and return an answer while the task is still running. Here, we are considering a similar scenario: a request is made, and the server has to do some processing on the request. Ideally, we want to separate the high time-demanding parts from the view processing flow, so we run those parts in a separate task. Now, let's suppose we have to do some database operations both in the view and the task when the request happens. If not done carefully, those operations can be a source for issues that can be hard to track. -
Metaprogramming and Django - Using Decorators
While programming is about, in some way, doing code to transform data, metaprogramming can be seen as the task of doing code to change code. This category is often used to help programmers to enhance the readability and maintainability of the code, help with separation of concerns and respect one of the most important principles of software develop -
Django and React Boilerplate as an Asset in Software Development
Here at Vinta we believe that programmers, not processes, nor code, are the most important assets on software engineering. Due to that, we believe in using every tool available in order to facilitate our programmers' lives. One of our favorites is our boilerplate. If you are unfamiliar with the concept, a boilerplate is "any code block that is reus -
How I test my DRF serializers
How I test my DRF serializers In this blog post, I will show the whats and whys on testing Django REST Framework serializers. First, some context. Here is the model setup we are going to use for this example: from django.db import models class Bike(models.Model): COLOR_OPTIONS = (('yellow', 'Yellow'), ('red', 'Red&# -
Don't forget the stamps: testing email content in Django
When developing a web app how often do you check the emails you send are all working properly? Not as often as your web pages, right? That's ok, don't feel guilty, emails are hard to test and they are often someone's else responsibility to write and take care. This doesn't mean we should give up on them. There are some things we can do to prevent e -
Contributing to Django Framework is easier than you think
For those who are starting to code and wish to make open source, sometimes it is hard to start. The idea of contributing with that fancy and wonderful lib that you love can sound a little bit scary. Lucky for us many of those libs have room for whoever is willing to start. They also give us the support that we need. Pretty sweet, right? Do you know -
Advanced Django querying: sorting events by date
Imagine the situation where our application has events (scheduled tasks, appointments, python conferences across the world) happening in different moments of time. Almost anything with a date attached to it. We want to display them in a simple list to the user. Given we are in February 2017 (the date this post was written), what would be the best w -
DjangoCon Europe 2017 was awesome!
DjangoCon Europe happened in one of the most historical cities in Italy! Florence was the most exciting place to be around in Europe, if you are a Django enthusiast, from April 3rd to April 7th. The event had the presence of some important names on it, like Andrew Godwin and Marc Tamlyn, both core developers at Django, and Tom Christie, author of t -
[pt-BR] Organizando o Django Girls Recife
No Brasil, as mulheres são maioria nas escolas e universidades e representam 60% das pessoas que concluíram cursos superiores. Apesar disso, em cursos de exatas, representam apenas 20% do quantitativo. Esse cenário se repete não só no Brasil, mas em todo o mundo. Nas áreas tecnológicas não é diferente. TI é, ainda, um mundo majoritariamente masculino. Foi com o intuito de diversificar esse contexto que o Django Girls foi criado. -
Organizing Django Girls Recife
In Brazil, women are the majority in schools and universities and represent 60% of the people who have a university degree. Despite this, in STEM, they represent only 20% of the quantitative. This scenario is present not only in Brazil but all over the world. In technological areas, it’s no different. IT is still a mostly male world. It was with the intention of diversifying this context that the Django Girls was created. -
Going to Technical Events is Awesome: A DjangoCon Experience
We just got back from DjangoCon US! It was quite a marathon for us because Filipe Ximenes and I have been to PyBay and DjangoCon AU too, right before DjangoCon US. Besides having a great time presenting our talks, it was awesome to meet new people and reunite with old friends. From our blog, you’d guess that we really enjoy conferences. We do incentivize collaborators to attend them since we believe it's very important to keep in touch with the community. -
Multitenancy: juggling customer data in Django
Suppose you want to build a new SaaS (Software as a Service) application. Suppose your application will store sensitive data from your customers. What is the best way to guarantee the isolation of the data and make sure information from one client does not leak to the other? The answer to that is: it depends. It depends on the number of customers y -
Django REST Framework Read & Write Serializers
Django REST Framework (DRF) is a terrific tool for creating very flexible REST APIs. It has a lot of built-in features like pagination, search, filters, throttling, and many other things developers usually don't like to worry about. And it also lets you easily customize everything so you can make your API work the way you want. There are many gene -
Taming Irreversibility with Feature Flags (in Python)
Feature Flags are a very simple technique to make features of your application quickly toggleable. The way it works is, everytime we change some behavior in our software, a logical branch is created and this new behavior is only accessible if some specific configuration variable is set or, in certain cases, if the application context respects some -
Reactify Django
# Reactify Django is coming. ... -
Django development with Docker — Testing, Continuous Integration and Docker Hub
At the end of my last post about Django development with Docker, we saw how to improve our development environment by implementing these features:Accessing our database from outside the containerInstalling different requirements for each environmentUsing different settings for each environmentEnabling server reloading on code changesBut we did not execute or write any test, even more we are not using any kind of Continuous Integration. Let’s see how to implement these features.IntroductionDuring this post, we will address the following points:How can we configure and run our tests inside a Docker container?How can we integrate our application with a Continuous Integration (C.I.) server and implement Continuous Delivery?Is it possible to Upload our images to Docker Hub from our C.I. server?While we configure travis ci as our Continuous Integration server, we will run our tests and upload a new image to Docker Hub.Note: This post will not go deep in travis and docker hub explications, the main focus is in using them for our intentions.Writing & Running testsFirst, enumerate what we need to accomplish in this section:Install a test framework and configure it.Configure an in-memory database for themWrite some tests for our applicationRun our tests in a containerWe’re going to use pytest, a … -
Ansible provision/deploy setup
I never got around to write down the ansible setup I figured out (together with others, of course, at my previous job) for deploying/provisioning django websites. The whole setup (as a cookiecutter template) can be found in https://github.com/reinout/cookiecutter-djangosite-template . The relevant code is in the ansible/ directory. Note: this is a "cookiecutter template" from which you can generate a project so you'll see some {{ }} and {% %}: when you create the actual project these items will be filled in. My goal was to keep the setup simple and safe. With "safe", I mean that you normally cannot accidentally do something wrong. And it was intended for getting one website project onto the server(s). It is not a huge ansible setup to set up the whole infra in one fell swoop. First the inventory files: Yes, multiple: there are two of them. production_inventory and staging_inventory. The safe aspect is that we used to have a single inventory file with [production] and [staging] headings in it. If you wanted to update staging, you had to add --limit staging on the command line. If you forgot that... With two separate files, you never have this problem. Accidents are much less likely … -
GeoDjango and PostgreSQL
I recently had to set up GeoDjango on a site that used PostgreSQL as a database. As the online instructions for doing this were less than totally clear, I decided to write down how I did it. -
Best React Books 2018
List of current React/JavaScript books. -
Django Local 404 Page
Learn how to display and customize a 404 page locally. -
Angular 6|5 Tutorial: Integrating Angular with Django
In the previous Angular 6 tutorial we've seen how to build a CRUD web application with a Django REST framework API back-end. In this tutorial we'll see how we can integrate the Angular 6 front-end with the Django back-end. After creating both the back-end and front-end apps we need to integrate them i.e instead of taking the approach where both applications are completely separated we'll serve the front-end application using a Django view. In development we'll have both Django development server and Angular/Webpack dev server running but for production we'll only need a Django server. To use this approach you need to tweak the Webpack settings of your front-end project, use the webpack-bundle-tracker (from npm) and use the django-webpack-loader package (from PyPI) The webpack-bundle-tracker is a Webpack plugin that generates a stats file containing meta data information about the assets of your front-end application generated by Webpack. We'll start by installing the webpack-bundle-tracker module then update the Webpack configuration file to make use of this plugin. npm install webpack-bundle-tracker --save Next you need to eject the Webpack configuration from the Angular 6 CLI using ng eject If the ejection is successful you'll find a webpack.config.js in the root of your … -
QuerySet Filters on Many-to-many Relations
Django ORM (Object-relational mapping) makes querying the database so intuitive, that at some point you might forget that SQL is being used in the background. This year at the DjangoCon Europe Katie McLaughlin was giving a talk and mentioned one thing that affects the SQL query generated by Django ORM, depending on how you call the QuerySet or manager methods. This particularity is especially relevant when you are creating your QuerySets dynamically. Here it is. When you have a many-to-many relationship, and you try to filter objects by the fields of the related model, every new filter() method of a QuerySet creates a new INNER JOIN clause. I won't discuss whether that's a Django bug or a feature, but these are my observations about it. The Books and Authors Example Let's create an app with books and authors, where each book can be written by multiple authors. # -*- coding: UTF-8 -*-from __future__ import unicode_literalsfrom django.db import modelsfrom django.utils.translation import ugettext_lazy as _from django.utils.encoding import python_2_unicode_compatible@python_2_unicode_compatibleclass Author(models.Model): first_name = models.CharField(_("First name"), max_length=200) last_name = models.CharField(_("Last name"), max_length=200) author_name = models.CharField(_("Author name"), max_length=200) class Meta: verbose_name = _("Author") verbose_name_plural = _("Authors") ordering = ("author_name",) def __str__(self): return self.author_name@python_2_unicode_compatibleclass Book(models.Model): title = … -
Djangocon keynote: the naïve programmer - Daniele Procida
(One of my summaries of a talk at the 2018 European djangocon.) The naïve programmer is not "the bad programmer" or so. He is just not so sophisticated. Naïve programmers are everywhere. Almost all programmers wish they could be better. Whether you're Programming is a craft/art/skill. That's our starting point. Art can be measured against human valuation. In the practical arts/crafts, you can be measured against the world (if your bridge collapses, for instance). Is your craft something you do all the time, like landing a plane? Or are you, as programmer, more in the creative arts: you face the blank canvas all the time (an empty models.py). In this talk, we won't rate along the single axis "worse - better". There are more axes. "Technique - inept", "creative - dull", "judgment - uncritical" and sophistication - naïve. It is the last one that we deal with. What does it mean to be a sophisticated programmer? To be a real master of your craft? They are versatile and powerful. They draw connections. They work with concepts and ideas (sometimes coming from other fields) to think about and to explain the problems they have to solve. The naïve programmer will write, …