Add custom http header in RedirectView
<p>I want to add the http header but it does not work.
I'm trying to test solve by using the print, but it appears nothing</p>

<p>This is my code but not works:</p>

<pre><code>class MyRedirectView(RedirectView):

    def head(self, *args, **kwargs):
        response = HttpResponse()
        response['X-Robots-Tag'] = 'noindex'
        print('TEST')
        return response
</code></pre>

<p>What you have done here is to override the <code>head</code> method. Which is only used when a HTTP request of the type HEAD is made to your url. You should override the <code>get</code> method or better still the dispatch method instead.</p>

<pre><code>class MyRedirectView(RedirectView):

    def dispatch(self, *args, **kwargs):
        response = super(MyRedirectView,self).dispatch(*args, **kwargs)
        response['X-Robots-Tag'] = 'noindex'
        print('TEST LOL')
        return response
</code></pre>

python django http-headers django-class-based-views