Django blog posts

How to setup Django with Pytest on GitHub Actions

Someone recently asked me

When is a good time to get automated testing setup on a new Django project?

The answer is "now". There are other good times, but now is best. In this post I'll briefly make my case for why, and show you an example of a minimal …

My (free) Django monitoring stack for 2022

You've built and deployed a website using Django. Congrats! After that initial high of successfully launching your site comes the grubby work of fixing bugs. There are so many things that can will go wrong. Pages may crash with 500 errors in prod, but not locally. Some offline tasks never …

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 …

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 …

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 …

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 …

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 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:

dummy-threads-empty

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 …

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 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 …

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 …

Page 1 / 2