Blog / Django

How to enable 2FA in the Django admin

July 14, 2021

I remember the first time I've used 2FA (two-factor authentication) was over 12 years ago when I worked as a sysadmin/netadmin in a Windows environment.  We had to purchase this RSA appliance/server and pay separate licenses for each user in the system.

Back in those days, we also used these keyfobs with a simple screen showing the 6-digit number that automatically refreshes every x seconds.  I actually thought those were really cool and when they …

How to reset the primary key sequence in PostgreSQL with Django

March 19, 2019

I was working on some fairly big features involving new Django models for one of our apps and when I pushed to our staging environment, I got this error during deployment at the database migration step:

duplicate key value violates unique constraint "auth_permission_pkey" DETAIL: Key (id)=(55) already exists

It looks like new records were getting added to the auth_permission table. I was puzzled as I didn't make any changes related to the Django auth app. …

Django 2.1 SameSite cookie issue with Safari 12

February 16, 2019

We just ran into this issue two days ago as we've recently upgraded the Django version for one of our Shopify apps to version 2.1.

We had a user tried to use the app and he kept getting redirected to the login page during the OAuth flow. He then tried it on Chrome and it worked fine so we narrowed down the issue to his web browser, which was Safari, specifically version 12 of Safari …

How to check if your Python app supports TLS 1.2

June 3, 2018

As you may have already heard, the Payment Card Industry (PCI) will be requiring everyone to use at least TLS 1.1 (1.2 is recommended) to meet their data security standard starting on June 30, 2018. Other services, such as PyPI, will be requiring only TLS 1.2 connections on the same date as well.

You need to make sure that the version of Python you're using and related packages support TLS 1.2 or a bunch …

How to add full-text search to your Django app (with a PostgreSQL backend)

September 25, 2017

In Django 1.10, the django.contrib.postgres.search module was added to make it really easy to use PostgreSQL's full text search engine with a Django app.

I currently use it for this blog, Remote Python's job and developer search, and our knowledge base for Highview Apps. I'm really impressed with how good the search is and how little code is needed to get it working. Unless you have huge amounts of data/traffic and need really …

Older