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

Python tricks

Posted on 2018-10-03 in Trucs et astuces • Tagged with Python

Inspect TLS certificates with requests

Use the snippet below to capture and inspect the certificates of a distant site and its chain with requests.

import requests

HTTPResponse = requests.packages.urllib3.response.HTTPResponse
orig_HTTPResponse__init__ = HTTPResponse.__init__
def new_HTTPResponse__init__(self, *args, **kwargs):
    orig_HTTPResponse__init__(self, *args, **kwargs …

Continue reading

Deploy your source maps to Rollbar with Ansible

Posted on 2018-07-16 in Trucs et astuces • Tagged with Rollbar, Python, Ansible

I recently had to integrate Rollbar (a service to track errors) with a JS application. One nice thing about Rollbar is that if you provide it with source maps, it will point to you where the error is in the original unminified code.

Since the application is deployed with Ansible …


Continue reading

Timeout a function in python

Posted on 2018-06-02 in Trucs et astuces • Tagged with Python

You can use signals and a context manager to acheive this. The idea is to register a function that will raise an exeption when the alarm signal is received and schedule the alarm signal for the timeout.

import signal
from contextlib import contextmanager


@contextmanager
def timeout(time):
    # Register a function …

Continue reading

Some tips for django

Posted on 2018-05-21 in Trucs et astuces • Tagged with Python, Web, Django


Continue reading

How to cache Python module in Gitlab CI

Posted on 2017-08-20 in Trucs et astuces • Tagged with gitlab, ci, Python

By default, pip cache will be in ~/.pip. However, this folder cannot be cached by Gitlab. The trick is to force pip to use a folder located in the build directory with the --cache-dir option. You can then cache this folder.

For instance, you can use .pip as in the …


Continue reading

Extraire le HTML d'un email au format mbox

Posted on 2017-08-07 in Trucs et astuces • Tagged with mail, Python

Voici un petit script Python pour convertir un mail au format mbox en HTML. Pour que le script fonctionne, il faut soit que le corps du message soit du HTML (recommandé) soit que la première pièce jointe du message contienne le message en HTML.

Par défaut, le script traitera tous …


Continue reading

Create python virtual enviroments on Windows

Posted on 2017-06-11 in Trucs et astuces • Tagged with Python

  1. Before creating the venv you will need to open a PowerShell terminal as root and run the commands below to allow the script that activates the virtual env to run:

    cd ..
    Set-ExecutionPolicy Unrestricted
    
  2. Create the venv. Run in a terminal as a normal user: python3 -m venv .venv If the …


Continue reading