Weird test behavior in my Django project test suite after an IntegrityError

Posted on 2024-12-01 in Programmation • Tagged with Python, Web, Django

Recently I encountered a very weird behavior in my Django project test suite. I created a view that caught an IntegrityError from the database (caused by duplicates in a unique index). When this error occurs, I want to respond with a 409 - CONFLICT status code and an error message.

TL …


Continue reading

Django async

Posted on 2023-12-10 in Programmation • Tagged with Web, Django, Python

Now that Django is fully async (views, middleware and ORM), I though it was a good time to test how it behaves when run asynchronously. I’ll try to keep this article concise with only relevant data and resources. Code can be seen in a sample project so you can …


Continue reading

Exploring a weird HTTP issues

Posted on 2022-05-04 in Programmation • Tagged with Python, Django, nginx, GCP, devops

Today I'd like to explain how I tried to solve a weird HTTP issues that I found at work. I hope you will find the method and the trials I used the useful/interesting if/when you will encounter something similar.

The issue was this: I needed to dynamically generate …


Continue reading

How to avoid CSRF token issues with Django when running on different sub-domains

Posted on 2022-02-13 in Trucs et astuces • Tagged with Python, Django

If you deploy multiple Django websites on your infrastructure on various subdomains, you may get issues about invalid CSRF tokens. This is happening either because:

  • You erase the cookie by using the same domain. For instance, if you have your prod API at api.jujens.eu and pre-production one at …

Continue reading

Build a sequence that is reset everyday

Posted on 2021-04-08 in Programmation • Tagged with Django, Python, PostgreSQL

How to create a database sequence that will be reset everyday? That is a sequence that will get one the first time of each day? It sounds easy but it's not that much.

Note

This article will focus on PostgreSQL since it's the database I use. A similar solution may …


Continue reading

Deploy a React app in kuberentes

Posted on 2021-04-01 in Trucs et astuces • Tagged with devops, k8s, kubernetes, Django, Python

I recently deployed a React app in kubernetes. It was initially deployed directly in a public bucket: I have an API that is already hosted on kubernetes, but the app itself is made only of static files, so it made sense. However, requirements for my app changed and I required …


Continue reading

Manage static files for Django when deployed on kubernetes

Posted on 2021-03-31 in Trucs et astuces • Tagged with devops, k8s, kubernetes, Django, Python

This will be a continuation of my article Some tips to deploy Django in kubernetes. In this previous article, I talked about generic tips you should apply to deploy Django into kuberentes. Here, I'll focus on static files.

If you don't already know that, gunicorn (or any other app server …


Continue reading

Some tips to deploy Django in kubernetes

Posted on 2021-03-29 in Trucs et astuces • Tagged with devops, k8s, kubernetes, Django, Python

I am not going to go into details in this article about how you can deploy Django in kubernetes. I am just going to highlight the main points you should pay attention to when deploying a Django app. I expect you to have prior knowledge about how to deploy an …


Continue reading

Use a dedicated user to run your database migrations on PostgreSQL

Posted on 2021-03-10 in Blog • Tagged with Django, PostgreSQL

I'll detail here how to use one user to apply your migrations and one to run you site. This method can be applied to any framework and environment as long as your database is PostgreSQL. It's of course possible to do with other databases, but the SQL syntax to achieve …


Continue reading

Should you build a SPA?

Posted on 2020-06-15 in Programmation • Tagged with JavaScript, Web, Django

This article is an update to a previous article why you want to build a SPA which I think was laking some nuance and precision. Reading this article is not required to read this one. I'm writing this update because SPAs are very popular and I recently though more about …


Continue reading