django-planet

Blog: Adam Johnson

web https://adamj.eu/
Author Adam Johnson

How to Safely Pass Data to JavaScript in a Django Template

Oct. 5, 2022 » Adam Johnson » [Archived Version]

You want to pass your data from your Django view to JavaScript, in your template. And, you want to do it securely, with no risk of accidentally allowing malicious code injection. Great, this is the post for you! We’re going to look at the problems with templating JavaScript, then …

Read More

Use partial() With Django’s transaction.on_commit() to Avoid Late-Binding Bugs

Aug. 21, 2022 » Adam Johnson » [Archived Version]

Django’s transaction.on_commit() allows you to run a function after the current database transaction is committed. This is useful to ensure that actions with external services, like sending emails, don’t run until the relevant data is definitely saved. Although Django’s documentation says that on_commit() takes a “function …

Read More

Use partial() With Django’s transaction.on_commit() to Avoid Late-Binding Bugs

Aug. 21, 2022 » Adam Johnson » [Archived Version]

Django’s transaction.on_commit() allows you to run a function after the current database transaction is committed. This is useful to ensure that actions with external services, like sending emails, don’t run until the relevant data is definitely saved. Although Django’s documentation says that on_commit() takes a “function …

Read More

How to Run a Django Migration “By Hand”

June 28, 2022 » Adam Johnson » [Archived Version]

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. But sometimes it can be necessary to run migrations “by hand” in your database’s …

Read More

How to Run a Django Migration “By Hand”

June 28, 2022 » Adam Johnson » [Archived Version]

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. But sometimes it can be necessary to run migrations “by hand” in your database’s …

Read More

How to Patch Requests to Have a Default Timeout

June 22, 2022 » Adam Johnson » [Archived Version]

Python’s requests package is very popular. Even if you don’t use it directly, it’s highly likely one of your dependencies does. One wrinkle in requests’ design is that it has no default timeout. This means that requests can hang forever if the remote server doesn’t respond …

Read More

How to Patch Requests to Have a Default Timeout

June 22, 2022 » Adam Johnson » [Archived Version]

Python’s requests package is very popular. Even if you don’t use it directly, it’s highly likely one of your dependencies does. One wrinkle in requests’ design is that it has no default timeout. This means that requests can hang forever if the remote server doesn’t respond …

Read More