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

Use the same function as context manager and decorator

Posted on 2022-09-25 in Trucs et astuces • Tagged with Python

I recently learned that context managers created with @contextmanager can be used either as a context manager or a decorator:

from contextlib import contextmanager

@contextmanager
def test_context():
    print('Entering')
    yield
    print('Leaving')

with test_context():
    print('Inside')

@test_context()
def test_decorated():
    print('Decorated')

test_decorated()

We will yield:

Entering
Inside
Leaving

Entering
Decorated …

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

PWAs and Django

Posted on 2020-02-29 in Programmation • Tagged with Python, Django, PWA, JavaScript

In this article, I'll guide you to create a PWA with the Django framework. All the code for this project is available under my gitlab account. You will find in each sections links to the relevant commits to help you follow. If something is not clear or if you have …


Continue reading

PyCharm tips

Posted on 2019-03-10 in Trucs et astuces • Tagged with Python, IDE, PyCharm

View print output immediately

Add PYTHONUNBUFFERED=1 in run config or .env (only use .env if you use the plugin). This is meant to immediately view the output …


Continue reading