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

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  django  s3  minio