124 Posts Tagged ‘django’

(All tags.)


How to Run a Django Migration “By Hand”

You can lead a pegasus to the database, but you can’t force it to migrate.

Normally your Django project’s deploy process runs the migrate command, and that takes care of updating your database as necessary. Especially on smaller databases, Django’s migration system can “just do it” for you.

Read more...

How to Patch Requests to Have a Default Timeout

Summon forth the armies, but with a timeout of five seconds.

Python’s requests package is very popular. Even if you don’t use it directly, it’s highly likely one of your dependencies does.

Read more...

How to optimize PostgreSQL queries from Django using pgMustard

Well, that cuts the mustard.

Slow queries happen, and when they do, it can be tough to dissect why they’re slow. This difficulty is compounded by using Django’s ORM, since it generates the SQL for you, so you may have little idea of the actual queries “under the hood”.

Read more...

How to Be a Teapot in Django

Lift me up, and pour me out.

HTCPCP, or Hyper Text Coffee Pot Control Protocol, was published as an April Fool’s joke 24 years ago today. It’s an HTTP extension for controlling coffee pots, and whilst it is a joke, it appears in various places around the web.

Read more...

How to Make Django Raise an Error for Missing Template Variables

Who dropped the {{ variable }} ?

It’s all too easy to forget to pass a variable to your template, or make a typo in a variable name. Unfortunately, it can be quite hard to debug such mistakes, since Django’s default behaviour is to ignore the problem and render an empty string.

Read more...

You Probably Don’t Need Django’s get_user_model()

Which way to the User model?

Django’s authentication system, django.contrib.auth, provides a built-in User model class. You can swap this to a different class with the AUTH_USER_MODEL setting, most easily at the start of the project.

Read more...

django-htmx Now on Read the Docs

Artist’s impression of my writing desk.

I’ve just released django-htmx 1.9.0. As part of this release, it now has a documentation site built with Sphinx, hosted on Read the Docs at django-htmx.readthedocs.io.

Read more...

Announcing WhiteNoise 6

I guess, like the white keys let you make noise, white - noise, whitenoise. Get it?

WhiteNoise is a simple solution to serving static assets. It lets you skip configuring a separate web server for your static assets, and serve them straight from Django. It’s a brilliant tool. I’ve used it for years on various projects, and I’ve recommended it many times, and mentioned it in several blog posts.

Read more...

How to Set Up Source Maps with Django

“Now where on this map is node_modules?”

Source maps are files that map your minified CSS or JavaScript back to the original code. They allow you to use your browser’s development tools to debug minified code as if it were the original. Also some error capture tools, such as Sentry, can use source maps to report errors for the original code.

Read more...

A Problem with Duplicated Mutable Constants

Hey! You’re just like me!

Here’s a small problem I’ve seen where several modules share versions of the same “constant” variable. It came up in the context of a Django project with multiple settings files, but it could happen in different contexts.

Read more...