Matt Segal Dev

Django blog posts

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

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

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 …

Page 3 / 3