132 Posts Tagged ‘django’

(All tags.)

Django Settings Patterns to Avoid

Settings are the engine of your project.

Here are some potential mistakes made with Django settings that you can avoid.


Django-related Deals for Black Friday and Cyber Monday 2022

Discounts, discounts, read all about them!

Here are some Django-related deals for this year’s Black Friday (25th Nov) and Cyber Monday (28th Nov), including my own. For more deals on general Python-related products, see Trey Hunner’s post.


unittest’s new context methods in Python 3.11 (with backports)

A testing concerto

Python 3.11 only made one change to unittest, but it’s a good one: context manager methods. These methods can simplify setup and teardown logic in many cases, such as dynamic use of unittest.mock.


django-upgrade Mega Release 1.11.0

Some busy bees have contributed their fixes.

I just released version 1.11.0 of django-upgrade, a tool for automatically upgrading your Django project code. This release contains a lot of new features and fixes, thanks to new contributors including those at the Djangocon Europe sprints. Let’s look at the top changes.


Migrate PostgreSQL ID’s from serial to identity after upgrading to Django 4.1

Let me regale you with the ballad of the serial to identity column migration…

The Django 4.1 release notes feature this short, innocent-looking note:


How to implement a “dry run mode” for data imports in Django

This ram ain’t running anywhere fast, dry or not.

In data import processes it’s often useful to have a “dry run” mode, that runs through the process but doesn’t actually save the data. This can allow you to check for validity and gather statistics, such as how many records already exist in the database. In this post, we’ll look at how to implement a dry run mode in Django by using a database transaction and rolling it back.


How to Safely Pass Data to JavaScript in a Django Template

Let’s avoid Honk-TML injection!

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!


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

I am rather partial to a nice plant.

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.


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.


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.