News Results


What's the best thing about working for Octopus Energy?

An in-depth discussion about my employment at Octopus Energy.

What's the best thing about working for Octopus Energy?

An in-depth discussion about my employment at Octopus Energy.

What's the best thing about working for Octopus Energy?

An in-depth discussion about my employment at Octopus Energy.

Django Friday Tips: Password validation

This time I’m gonna address Django’s builtin authentication system, more specifically the ways it allows us to build custom improvements over the already very solid foundations it provides. The idea for this post came from reading an article summing up some considerations we should have when dealing with passwords. Some of those considerations are about […]

Database Design Tutorial for Beginners

Databases are at the heart of every web application. Their design, or schema, is literally the blueprint for how all information is stored, updated, and accessed. However learning about databases …

HTMX, Django list_editable, and ManyToMany relationships in Django Admin

A quick demonstration of how I use HTMX in the Django Admin to hack in a ManyToMany relationship, kind of like using list_editable

Django Favicon Tutorial

This tutorial explains how to add a favicon to a Django website. The trick is it requires configuring your `static` files properly. To start things off, create a local directory …

Official Django REST Framework Tutorial - A Beginners Guide

This is a beginner-friendly guide to the official Django Rest Framework [tutorial](http://www.django-rest-framework.org/tutorial/1-serialization/). If you have struggled to complete the official tutorial on your own, consider this guide a good place …

Django Polls Tutorial API

The [polls tutorial](https://docs.djangoproject.com/en/dev/intro/tutorial01/) is the official guide to Django. As a fun exercise, I wanted to show how little code it takes to transform it into a robust API using …

How to Learn Django (2020)

As a “batteries-included” web framework, Django comes with a host of built-in features and a correspondingly steep learning curve for newcomers. In this post, I discuss what you need to …

Django Best Practices: Referencing the User Model

Django has a powerful, built-in [user authentication system](https://docs.djangoproject.com/en/dev/topics/auth/default/) that makes it quick and easy to add [login, logout, and signup functionality](https://learndjango.com/tutorials/django-login-and-logout-tutorial) to a website. But how should a Django developer …

Django Best Practices: Custom User Model

Django ships with a built-in [User model](https://docs.djangoproject.com/en/3.1/ref/contrib/auth/#django.contrib.auth.models.User) for authentication and if you'd like a basic tutorial on how to implement log in, log out, sign up and so on see …

Django Hosting & Deployment Options

[Django](https://www.djangoproject.com/) websites can be deployed on any number of hosting providers. The first choice is deciding whether to use a Platform-as-a-service (PaaS) option or a virtual private server (VPS). A …

Django Static Files and Templates

Static files like CSS, JavaScript, and fonts are a core piece of any modern web application. Django provides tremendous flexibility around _how_ these files are used, however this often leads …

Django Log In with Email not Username

Django was first released in 2005 and since then a lot has changed in web development, notably the predominant pattern at the time of using username/email/password has been simplified to …

Django Hello, World 5 Different Ways

Django is a "batteries-included" framework that comes with built-in scaffolding provided by the `startproject` command and the general concepts of apps. But, actually, Django provides incredible flexibility if desired around …

Make tests a part of the app

Today I am going to discuss quite a new idea for Python users, an idea of making tests a valuable part of your application. Let’s jump into it. Current status Right now the status-quo for source code/tests dualism is that you ship source code to your library users and most often do not include your tests in any manner. Sometimes people also attach the tests/ folder to your release, so they are just laying around just in case. Most of the time they are useless to the end-user. And what is…

How MDN's site-search works

tl;dr; Periodically, the whole of MDN is built, by our Node code, in a GitHub Action. A Python script bulk-publishes this to Elasticsearch. Our Django server queries the same Elasticsearch via /api/v1/search. The site-search page is a static single-page app that sends XHR requests to the /api/v1/search endpoint. Search results' sort-order is determined by match and "popularity". Jamstack'ing The challenge with "Jamstack" websites is with data that is too vast and dynamic that it doesn't make se…

Django Friday Tips: Subresource Integrity

As you might have guessed from the title, today’s tip is about how to add “Subresource integrity” (SRI) checks to your website’s static assets. First lets see what SRI is. According to the Mozilla’s Developers Network: Subresource Integrity (SRI) is a security feature that enables browsers to verify that resources they fetch (for example, from […]

I'm Building a Search Engine for the Django Ecosystem

Frustrated with Google, I decided to build a focused search engine to see if it can deliver better results. My first experiment covers the Django ecosystem.

Django Async Task Queue with Postgres (no Kafka, Rabbit MQ, Celery, or Redis)

Quickly develop async task queues with only django commands and postgresql. I dont need the complexity of Kafka, RabbitMQ, or Celery.

Docker, Django, Traefik, and IntercoolerJS is My Go-To Stack for Building a SaaS in 2021

I provide a deeper-dive on the tech stack I like to use in 2021. It is simple, easy to work with, and allows you to grow out of it when the time comes. Updated for 2021!

Recap of 2020 and Resolutions for 2021

Recap of 2020 I got a job saving the planet For years I've been worried about climate change. I've tried to live a mostly ecologically friendly life, and this year I dived in with making compost for the garden. However, seeing the lack of consistent political will to correct the problem has had me worried. So I was delighted that when I started to look for jobs in the autumn I was contacted by several firms attempting to address the problem. I've always thought that finance is a great motiv…

Django Friday Tips: Permissions in the Admin

In this year’s first issue of my irregular Django quick tips series, lets look at the builtin tools available for managing access control. The framework offers a comprehensive authentication and authorization system that is able to handle the common requirements of most websites without even needing any external library. Most of the time, simple websites […]

Using MinIO to upload to a local S3 bucket in Django

Hi everyone! Some weeks ago I was doing a demo to my teammates, and one of the things that was more suprising for them was that I was able to do S3 uploads locally using “MinIO”. Let me set the stage: Imagine you have a Django ImageField which uploads a picture to a AWS S3 bucket. How do you setup your local development environment without using a “development” AWS S3 Bucket?

How to create a celery task that fills out fields using Django

Hi everyone! It’s been way too long, I know. In this oportunity, I wanted to talk about asynchronicity in Django, but first, lets set up the stage: Imagine you are working in a library and you have to develop an app that allows users to register new books using a barcode scanner. The system has to read the ISBN code and use an external resource to fill in the information (title, pages, authors, etc.

Generating random avatar images in Django/Python

tl;dr; <img src="/avatar.random.png" alt="Random avataaar"> generates this image: (try reloading to get a random new one. funny aren't they?) When you use Gravatar you can convert people's email addresses to their mugshot. It works like this: <img src="https://www.gravatar.com/avatar/$(md5(user.email))"> But most people don't have their mugshot on Gravatar.com unfortunately. But you still want to display an avatar that is distinct per user. Your best option is to gene…

How to setup Django with React

It's not too hard to get started with either Django or React. Both have great documentation and there are lots of tutorials online. The tricky part is getting them to work together. Many people start with a Django project and then decide that they want to "add React" to it …

Higher Kinded Types in Python

dry-python/returns@0.15 is released! And it means that now anyone can use our Higher Kinded Types emulation in their projects. In this post I will explain: What Higher Kinded Types (HKTs) are and why they are useful How they are implemented and what limitations there are How can you use them in your own projects Without further ado, let’s talk about typing! Simple types Typing is layered. Like a good cake. There are at least three layers that we are going to cover. Simple (or fla…

A Django project blueprint to help you learn by doing

There's an awkward point when you're learning Django where you've done the official tutorial and maybe built a simple project, like a to-do list, and now you want to try something a little more advanced. People say that you should "learn by building things", which is good advice, but it …

How to use both camelCase and snake_case in your frontend and backend

Python uses snake_case variable naming while JavaScript favours camelCase. When you're buiding an web API with Django then you'll be using both langauges together. How do you keep your styles consistent? You could just use one style for both your frontend and backend, but it looks ugly. Perhaps this is …

Django Friday Tips: Inspecting ORM queries

Today lets look at the tools Django provides out of the box to debug the queries made to the database using the ORM. This isn’t an uncommon task. Almost everyone who works on a non-trivial Django application faces situations where the ORM does not return the correct data or a particular operation as taking too […]

August 2020 Courses

Live, Interactive, Online Courses For years Audrey and I have travelled giving in-person training sessions. With current events being what they are, I've switched to giving live, online, interactive trainings using Zoom meeting software. This has involved some major refactoring of content. Here are the upcoming courses on my calendar: August 14: Django Best Practices the Two Scoops Way August 21, 22, 23: Django Crash Course Live

How to manage logs with Django, Gunicorn and NGINX

So you want to run a Django app using NGINX and Gunicorn. Did you notice that all three of these tools have logging options? You can configure Django logging, Gunicorn logging, and NGINX logging. You just want to see what's happening in your Django app so that you can fix …

Is Django too slow?

Does Django have "bad performance"? The framework is now 15 years old. Is it out of date? Mostly, no. I think that Django's performance is perfectly fine for most use-cases. In this post I'll review different aspects of Django's "performance" as a web framework and discuss how you can decide …

How to make your Django project easy to move and share

You need your Django project to be portable. It should be quick and easy to start it up on a new laptop. If it isn't portable, then your project is trapped on your machine. If it gets deleted or corrupted, then you've lost all your work! This issue comes up …

I'm Teaching A Live Online Django Crash Course

Course Announcement On July 16th and 17th of 2020, starting at 9AM PST (4PM UTC), I'll be running a live instruction of my beginner-friendly Django Crash Course. This is a live interactive class conducted via Zoom conferencing software. We're going to walk through the book together with students. If you get stuck, there will be at least two members of the Feldroy team available to help. Each course day will have two sessions each 3 hours long, as well as an hour-long break between sessions.…

How to find what you want in the Django documentation

Many beginner programmers find the Django documentation overwhelming. Let's say you want to learn how to perform a login for a user. Seems like it would be pretty simple: logins are a core feature of Django. If you google for "django login" or search the docs you see a few …

How to pull production data into your local Postgres database

Sometimes you want to write a feature for your Django app that requires a lot of structured data that already exists in production. This happened to me recently: I needed to create a reporting tool for internal business users. The problem was that I didn't have much data in my …

How to generate lots of dummy data for your Django app

It sucks when you're working on a Django app and all your pages are empty. For example, if you're working on a forum webapp, then all your discussion boards will be empty by default: Manually creating enough data for your pages to look realistic is a lot of work. Wouldn't …

How to automatically reset your local Django database

Sometimes when you're working on a Django app you want a fresh start. You want to nuke all of the data in your local database and start again from scratch. Maybe you ran some migrations that you don't want to keep, or perhaps there's some test data that you want …

How async should have been

In the last few years async keyword and semantics made its way into many popular programming languages: JavaScript, Rust, C#, and many others languages that I don’t know or don’t use. Of course, Python also has async and await keywords since python3.5. In this article, I would like to provide my opinion about this feature, think of alternatives, and provide a new solution. Colours of functions When introducing async functions into the languages, we actually end up with a split world. Now, s…

A tour of Django server setups

If you haven't deployed a lot of Django apps, then you might wonder: how do professionals put Django apps on the internet? What does Django typically look like when it's running in production? You might even be thinking what the hell is production? Before I started working a developer there …

How I manage multiple development environments in my Django workflow using Docker compose

Hi everyone! Last week I was searching how to manage multiple development environments with the same docker-compose configuration for my Django workflow. I needed to manage a development and a production environment, so this is what I did. Some descriptions on my data: I had around 20 env vars, but some of them where shared among environments. I wanted to do it with as little impact as possible. First, docker-compose help command The first thing I did was run a simple docker-compose --help, a…

Two Scoops of Django 3.x Released

We just released the early release (alpha) of the fifth edition of our book, titled Two Scoops of Django 3.x. The 3.x means we are supporting Django 3.0, 3.1, and 3.2 Long Term Support (LTS) releases, ensuring the content will be valid until April of 2024. So long as it is May 11, 2020, anywhere on planet Earth, the e-book version sells for just US$42.95! On May 12th, 2020, the price goes up to $49.95. Hurry up and get your book! For now, the e-book is just in PDF format and will be expand…

How to diagnose and fix slow queries with Django Debug Toolbar

Your Django views are running slowly and you want to make them faster, but you can't figure out what the issue is just by reading the code. Just as bad is when you're not sure if you're using the Django ORM correctly - how can you know if the code you …

Secure your Django API from DDoS attacks with NGINX and fail2ban

Hello everyone! Last week our Django API, hosted on an Amazon EC2 server was attacked by a botnet farm, which took our services down for almost the entire weekend. I’m not going to lie, it was a very stressful situation, but at the same time we learned a lot about how to secure our server from future DDoS attacks. For our solution we are using the rate-limiting functionality from NGINX and fail2ban, a program that bans external APIs when they break a certain set of rules.

Simple Django deployment part six: domain setup

We're very nearly done deploying our Django app. There's just one more thing we should take care of. Having a raw IP as our website address is kind of yucky, isn't it? You're not going to ask your friend, boss, or mum to visit 23.231.147.88 to check …

Simple Django deployment part five: deployment automation

Deploying our Django app involved a lot of different commands, right? It would suck to have to do all that over again, wouldn't it? Having to manually type all those commands again would be tedious, slow and easy to screw up. Even worse, the harder it is to deploy, the …

Simple Django deployment part four: run a service

So we've got a problem. Our Django app only runs when we're logged into the server via SSH and running Gunicorn. That's not going to work long term. We need to get Gunicorn running even when we're not around. In addition, if our Gunicorn server crashes because of some bug …

Simple Django deployment part three: deploy code

We've got our server set up, and our Django code is ready. Now we can actually deploy Django to our server. The goal of this section is to get a basic deployment done. We'll do some automation and introduce some extra tools later. In this section we'll cover: Windows line …

Simple Django deployment part two: local setup

We've got our server set up and ready to host our Django app, now let's focus on preparing our app for deployment. The goal of this section is to set up and test as much of the stuff that we'll be using in production. That way, we can debug issues …

Simple Django deployment part one: infrastructure

In order to deploy our Django app, we need a somewhere to run it: we need a server. In this section we'll be setting up our server in "the cloud". Doing this can be fiddly and annoying, especially if you're new, so we want to get it right first before …

Simple Django deployment: a guide

You're learning web development with Django. You've followed the official introductory tutorial and you can get a Django app working on your local computer. Now you want to put your web app onto the internet. Maybe it's to show your friends, or you actually want to use it for something …

Django Friday Tips: Feature Flags

This time, as you can deduce from the title, I will address the topic of how to use feature flags on Django websites and applications. This is an incredible functionality to have, specially if you need to continuously roll new code to production environments that might not be ready to be released. But first what […]

4 tips for debugging in Django

You've got a bug in your Django code and you can't quite figure out what's wrong. You know there's a problem, but you can't quite pin down where it's coming from. This post will share 4 tips which will help you speed up your bug catching. Dig deeper in your …

Quickly fix bugs in Django with Python's debugger

There's a bug in your Django code. You've tried to track down the problem with "print" statements, but it's such a slow, tedious process: Add a "print" statement to your code Refresh the page in your browser to re-run your code Look at the runserver console output for the "print …

How to save Django logs in production

You've deployed Django to a webserver and something has broken. There's an error somewhere. What happened? When you're debugging Django on your local computer, you can just throw a print statement into your code and check the output in the runserver logs. What about in production? Where do the logs …

How to view Django logs with Papertrail

You have a Django app running on a webserver and hopefully you're writing your logs to a file. If anything goes wrong you can search back through the logs and figure out what happened. The problem is that to get to your logs, you have to log into your server …

How to customise a class based view in Django

You've spend a little bit of time working on your Django app and you want to dip your toes into class-based views. The basic examples are simple enough, but once you want to do something more complicated, something more custom, you get stuck. How do you customise a class-based view …

Sentry is great for tracking Django errors

You've deployed a Django app to a webserver and now it's not working. Your app is throwing 500 Internal Server Errors - what's wrong? Why is this happening? It worked on my laptop!? Even worse is when a customer experienced an error 12 hours ago and you need to figure out …

How to restart Celery on file change

I use Celery and Django together a lot. My biggest pain when doing local development with Celery is that the worker process won't restart when I change my code. Django's runserver restarts on code change, why can't Celery? How can you set up your dev envrionent to force Celery to …

3 ways to deploy a Django backend with a React frontend

You're developing a web app with a Django REST backend and some sort of single page app frontend using React or Vue or something like that. There are many ways for you to run this app in production. There are a lot of choices that you need to make: Do …

How to deploy Django migrations

You've started learning Django, you've created a new Django app and you've deployed it to a Linux webserver in the cloud somewhere. It's all set up and running nicely. Now you want to make some more changes and you need to update your models. How do you deploy those model …

Fix long running tasks in Django views

What do you do if you have a Django view that runs too slow? Slow views are a bad user experience. Users hate waiting. Even worse, if the view takes too long to return a response, they will receive a "408 Request Timeout" error, completely ruining the website experience. Sometimes …

Simple scheduled tasks with Django Q

How do you run some code once a day in Django, or every hour? This post will explain how to set up scheduled code execution in Django using Django-Q. There are a lot of reasons you might want to run code on a schedule. You may want to: Process a …

Using Python, Django, and Boto3 with Scaleway Object Storage

This excerpt simply exists to help you understand how to use the popular boto3 library to work with Scaleway's Object Storage. You might also consider djang-storages.

Django Friday Tips: Testing emails

I haven’t written one of these supposedly weekly posts with small Django tips for a while, but at least I always post them on Fridays. This time I gonna address how we can test emails with the tools that Django provides and more precisely how to check the attachments of those emails. The testing behavior […]

Do not log

Almost every week I accidentally get into this logging argument. Here’s the problem: people tend to log different things and call it a best-practice. And I am not sure why. When I start discussing this with other people I always end up repeating the exact same ideas over and over again. So. Today I want to criticize the whole logging culture and provide a bunch of alternatives. Logging does not make sense Let’s start with the most important one. Logging does not make any sense! Let’s review…

Adding Metadata to PDFs

For both Django Crash Course and the forthcoming Two Scoops of Django 3.x, we're using a new process to render the PDFs. Unfortunately, until just a few days ago that process didn't include the cover. Instead, covers were inserted manually using Adobe Acrobat. While that manual process worked, it came with predictable consequences. Merging the PDFs This part was easy and found in any number of blog articles and Stack Overflow answers. Step 1: Install pypdf2 Step 2: Write a script as seen…

Conditional coverage

Recently I had to add python3.8 for our Python linter (the strictest one in existence): wemake-python-styleguide. And during this straight-forward (at first look) task, I have found several problems with test coverage that were not solved in Python community at all. Let’s dig into it. Environment-based logic The thing about this update was that python3.8 introduced a new API. Previously we had visit_Num, visit_Str, visit_NameConstant methods (we don’t really care about what they do, only n…

How to search in a huge table on Django admin

Hello everyone! We all know that the Django admin is a super cool tool for Django. You can check your models, and add/edit/delete records from the tables. If you are familiar with Django, I’m sure you already know about it. I was given a task: Our client wanted to search in a table by one field. It seems easy enough, right? Well, the tricky part is that the table has 523.

Building my own Screenshot-as-a Service with Docker, Django, and Selenium

Watch me embarrass myself as I publicly share and explore what it takes to make a screenshot as a service. See the site. Get the code.

Our New Django Book Has Launched!

Audrey and I wrote a new book titled Django Crash Course. You can get it right now on our website at roygreenfeld.com/products/django-crash-course. Right now it's in alpha, which means only the e-book is available. Later we'll produce it in print formats (perfect bound, spiral, and hardcover). As the book is in alpha, you're encouraged to submit bug reports to us for errors that you find. In turn we will give you credit for your contributions in not just the e-book, but also in the print paper…

Typed functional Dependency Injection in Python

Dependency injection is a controversial topic. There are known problems, hacks, and even whole methodologies on how to work with DI frameworks. A lot of people asked me: how can you use a lot of typed functional concepts together with traditional object-oriented dependency injection? And this question makes a lot of sense. Because functional programming is all about composition. And dependency injection is just magic. You get some almost random objects injected into some places of your code…

Django is My Go-to Application Framework for 2020

Django continues to be a rational and powerful choice to build your modern web application or SaaS.

How to have default/initial values in a Django form that is bound and rendered

Django's Form framework is excellent. It's intuitive and versatile and, best of all, easy to use. However, one little thing that is not so intuitive is how do you render a bound form with default/initial values when the form is never rendered unbound. If you do this in Django: class MyForm(forms.Form): name = forms.CharField(required=False) def view(request): form = MyForm(initial={'name': 'Peter'}) return render(request, 'page.html', form=form) # Imagine, in 'page.html' that it…

A Python and Preact app deployed on Heroku

Heroku is great but it's sometimes painful when your app isn't just in one single language. What I have is a project where the backend is Python (Django) and the frontend is JavaScript (Preact). The folder structure looks like this: / - README.md - manage.py - requirements.txt - my_django_app/ - settings.py - asgi.py - api/ - urls.py - views.py - frontend/ - package.json - yarn.lock - preact.config.js - build/ ... - src/ …

Complexity Waterfall

When talking about “bad code” people almost certainly mean “complex code” among other popular problems. The thing about complexity is that it comes out of nowhere. You start your fairly simple project, then one day you find it in ruins. And no one knows how and when it happened. But, this ultimately happens for a reason! Code complexity enters your codebase in two possible ways: with big chunks and incremental additions. And people are bad at reviewing and finding both of them. When a big c…

Testing Django Migrations

Dear internet, Today we have screwed up by applying a broken migration to the running production service and causing a massive outage for several hours… Because the rollback function was terribly broken as well. As a result, we had to restore a backup that was made several hours ago, losing some new data. Why did it happen? The easiest answer is just to say: “Because it is X’s fault! He is the author of this migration, he should learn how databases work”. But, it is counterproductive. Inst…

Update to speed comparison for Redis vs PostgreSQL storing blobs of JSON

Last week, I blogged about "How much faster is Redis at storing a blob of JSON compared to PostgreSQL?". Judging from a lot of comments, people misinterpreted this. (By the way, Redis is persistent). It's no surprise that Redis is faster. However, it's a fact that I have do have a lot of blobs stored and need to present them via the web API as fast as possible. It's rare that I want to do relational or batch operations on the data. But Redis isn't a slam dunk for simple retrieval because I don'…

Testing mypy stubs, plugins, and types

Have you ever tried to: Create complex generic types in your own project? Write distributable stubs for your library? Create custom mypy plugin? In case you try to do any of these, you will soon find out that you need to test your types. Wait, what? Let me explain this paradox in detail. The first tests for types in Python Let’s start with a history lesson. The first time I got interested in mypy, I found their testing technique unique and interesting. That’s how it looks like: […

Typechecking Django and DRF

As you have already know I love optional static typing. The thing is that sometimes it is not optional, but impossible. Because we have plenty of big untyped projects in Python’s ecosystem. Django and Django-Rest-Framework were two of them. Were. Because now they can be typed! Let me introduce TypedDjango organisation and stubs for django and drf. This is going to be a concise tutorial and getting started guide. Kudos I want to say a big “thank you” to @mkurnikov for leading the project a…

6 mac apps that fit everyone

You often can see lists of awesome apps that you are not going to use or ones that just do not fit you. This one is different. This list contains simple, yet very powerful productivity boosters that totally fits everyone. TLDR: Here’s the list of all mac apps I am using, they can be found in my dotfiles with the rest of my setup. Previous on-topic articles: Command line productivity Using better CLIs Dato That’s a new project from @sindresorhus. It is simple, yet amazing. For some re…

SongSearch autocomplete rate now 2+ per second

By analyzing my Nginx logs, I've concluded that SongSearch's autocomplete JSON API now gets about 2.2 requests per second. I.e. these are XHR requests to /api/search/autocomplete?q=.... Roughly, 1.8 requests per second goes back to the Django/Elasticsearch backend. That's a hit ratio of 16%. These Django/Elasticsearch requests take roughly 200ms on average. I suspect about 150-180ms of that time is spent querying Elasticsearch, the rest being Python request/response and JSON "paperwork". Cachi…

What is your SaaS app hosting setup and deployment workflows?

I am a lazy developer which means that I try to automate as much as possible. This is my personal tech stack that I use for most production-ready projects. It is repeatable, durable, and scalable.

8 useful dev dependencies for django projects

In this post I’m gonna list some very useful tools I often use when developing a Django project. These packages help me improve the development speed, write better code and also find/debug problems faster. So lets start: Black This one is to avoid useless discussions about preferences and taste related to code formatting. Now I […]

Build an XML sitemap of XML sitemaps

Suppose that you have so many thousands of pages that you can't just create a single /sitemap.xml file that has all the URLs (aka <loc>) listed. Then you need to make a /sitemaps.xml that points to the other sitemap files. And if you're in the thousands, you'll need to gzip these files. The blog post demonstrates how Song Search generates a sitemap file that points to 63 sitemap-{M}-{N}.xml.gz files which spans about 1,000,000 URLs. The context here is Python and the getting of the data i…

Generate a random IP address in Python

A fun trick to generate random, but seeded, IPv4 addresses in a Django app.

Best way to count distinct indexed things in PostgreSQL

`SELECT COUNT(*) FROM (SELECT DISTINCT my_not_unique_indexed_column FROM my_table) t`

Django ORM optimization story on selecting the least possible

This an optimization story that should not surprise anyone using the Django ORM. But I thought I'd share because I have numbers now! The origin of this came from a real requirement. For a given parent model, I'd like to extract the value of the name column of all its child models, and the turn all these name strings into 1 MD5 checksum string. Variants The first attempted looked like this: artist = Artist.objects.get(name="Bad Religion") names = [] for song in Song.objects.filter(ar…

Channels and Webhooks

Django is an awesome web framework for python and does a really good job, either for building websites or web APIs using Rest Framework. One area where it usually fell short was dealing asynchronous functionality, it wasn’t its original purpose and wasn’t even a thing on the web at the time of its creation. The […]

Django Friday Tips: Links that maintain the current query params

Basically when you are building a simple page that displays a list of items that contain a few filters you might want to maintain them while navigating, for example while browser through the pages of results. Nowadays many of this kind of pages are rendered client-side using libraries such as vue and react, so this […]

Django Friday Tips: Adding RSS feeds

Following my previous posts about RSS and its importance for an open web, this week I will try to show how can we add syndication to our websites and other apps built with Django. This post will be divided in two parts. The first one covers the basics: Build an RSS feed based on a […]

Django Friday Tips: Timezone per user

Adding support for time zones in your website, in order to allow its users to work using their own timezone is a “must” nowadays. So in this post I’m gonna try to show you how to implement a simple version of it. Even though Django’s documentation is very good and complete, the only example given […]

Django Friday Tips: Secret Key

One thing that is always generated for you when you start a new django project is the SECRET_KEY string. This value is described in the documentation as: A secret key for a particular Django installation. This is used to provide cryptographic signing, and should be set to a unique, unpredictable value. The rule book mandates […]

Django Friday Tips: Security Checklist

Security is one of those areas where it is very hard to know if everything is taken care of. So you have been working on this project for a while and you want to deploy it into a production server, there are several settings on this new environment that should differ from your development one. […]

Django Friday Tips: Managing Dependencies

This one is not specific of django but it is very common during the development of any python project. Managing the contents of the requirements.txt file, that sometimes grows uncontrollably can be a mess. One of the root causes is the common work-flow of using virtualenv, install with pip all the required libraries and then […]

Django friday tips: Switch the user model

In the most recent versions of django, you’re no longer attached to the default user model. So unlike what happened some time ago, when you had two models (User and Profile) “linked” together through an one-to-one relationship, nowadays you can extend or substitute the base user model. It is as simples as adding the following […]

Newsletters for Python web developers

The amount of new information that is added each day to the web is overwhelming, trying to keep up daily with everything about a given topic can be a time consuming process. One good way I found to tackle this problem and to avoid wasting a good chunk of my day searching and filtering through […]

Django Resources

As I said in earlier posts in this blog, when i build websites or webapps where there are no technology impositions, i usually choose to do it in Python and in most of the cases, that’s the equivalent to say i choose to do it in Django. Over the last year, since i started using […]

Where do news results come from?
News items are curated from a select group of feeds. Suggest a website or news feed we should add. (RSS is preferred). let us know.
Special thanks to Filip Němeček. Sources borrowed from DjangoBlogs.com
  • Simple CTO
  • sobolevn's blog
  • Roger Gonzalez's Blog
  • Gonçalo Valério's Blog
  • LearnDjango
  • Peter Bengtsson's Blog
  • Matthew Segal's Blog
  • pydanny