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}),
]
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
| 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…