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]Register all models with Django admin
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]Django: CSRF exempt view
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
Handling signals with 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.
[Read More]
ArgoCD Python Client
A simple Python client to interact with ArgoCD.
[Read More]GitLab: User owned projects report
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]Local S3 with MinIO in Django
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]
Python
These days Python is my language of choice for both simple scripts and more complex backend applications, usually in combination with [[django]]