Python
Posts tagged with #python
Total: 10
Notes
| 2025-04-14
(updated 2025-10-25)
| 1 min read
#git
#pip
#python
Install a pip package from a git repo, using a specified git reference:
Read more…
Notes
| 2025-01-02
(updated 2025-10-25)
| 1 min read
#django
#python
I often find myself replacing an existing MVP based on static html with a Django app,
or just needing to preserve some old URL scheme.
This is the code I use to do that:
from django.shortcuts import redirect
def redirect_view(request, redirectable, permanent=True):
return redirect(redirectable)
Which can then be used like this:
from django.urls import path
from . import views
urlpatterns = [
path("old-url/", views.redirect_view, {"redirectable": "new_view"}),
path("some-thing/", views.redirect_view, {"redirectable": "some_thing_new", permanent=False}),
]
A Helper Container
Posts
| 2023-12-04
(updated 2025-10-23)
| 1 min read
#containers
#debugging
#k8s
#python
Debugging container workloads can be a challenge sometimes, especially when running them in k8s,
behind a reverse proxy or in other, possibly complex, traffic flow scenarios.
Read more…
Notes
| 2023-11-16
(updated 2025-10-25)
| 1 min read
#django
#python
Sometimes, mostly when throwing together a quick idea or MVP, it can be useful to just register all models with the admin
and leave proper customization for later.
Read more…
Notes
| 2023-09-17
(updated 2025-10-25)
| 1 min read
#django
#python
Django’s CSRF protection is usually a great thing,
but when building (API) endpoints meant to be accessed by scripts/third parties it gets in the way of that.
This is how to disable it:
For a class based view
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt
@method_decorator(csrf_exempt, name='dispatch')
class MyView(View):
pass
For a function based view
from django.views.decorators.csrf import csrf_exempt
@csrf_exempt
def my_view(request):
pass
Notes
| 2023-05-10
(updated 2025-10-25)
| 2 min read
#python
When building a Python script that is long running or has to manage some state on termination it is helpful to handle a couple of signals:
SIGINT: The signal sent when pressing Ctrl+C
SIGTERM and SIGQUIT: Meant to terminate the process, sent by kill and process managers like systemd or supervisord
Handling them is possible with Pythons signals library:
import signals
class SignalHandler:
stop = False
def __init__(self):
# Ctrl+C
signal.signal(signal.SIGINT, self.exit_gracefully)
# Supervisor/process manager signals
signal.signal(signal.SIGTERM, self.exit_gracefully)
signal.signal(signal.SIGQUIT, self.exit_gracefully)
def exit_gracefully(self, *args):
self.stop = True
Example 1: Simple loop
The simplest example is using the SignalHandler as the condition on the loop
and have code to stop gracefully below the loop.
Read more…
Notes
| 2023-01-01
(updated 2025-10-25)
| 3 min read
#argocd
#python
A simple Python client to interact with ArgoCD.
Read more…
Notes
| 2022-08-17
(updated 2025-10-25)
| 1 min read
#gitlab
#python
Export a CSV formatted report of projects in user-namespace on a GitLab instance.
This is especially useful if you think about limiting or disabling this feature.
Read more…
Notes
| 2021-11-06
(updated 2025-10-25)
| 2 min read
#django
#minio
#python
#s3
In production I would consider it best practice to use a S3 solution for serving assets. Namely static files and user-generated media.
This describes my setup on how to do this locally too.
The main benefit for me is that there is less of a difference between environments and I can test S3 specific features in my app.
Setup
I will assume a already working Django project and MacOS with [[brew]] installed,
but brew specific parts are easilly replicated on different systems using their native package managers.
Read more…
Notes
| 2020-01-01
(updated 2025-10-25)
| 1 min read
#python
#slashpage-uses
These days Python is my language of choice for both simple scripts and more complex backend applications, usually in combination with [[django]]