[Answered ]-How to add allow response header to all django views?

1👍

For class-based views, you can add a mixin that will determine this. Indeed:

class AllowViewMixin:
    def dispatch(self, *args, **kwargs):
        response = super().dispatch(*args, **kwargs)
        response.headers['Allow'] = ', '.join(self._allowed_methods())
        return response

then you can mix this in the class-based views, for example a ListView:

class MyListView(AllowViewMixin, ListView):
    # …

Leave a comment