2024-10-03 06:31:52 发布
网友
我想添加http头,但它不起作用。 我试着用印刷品来测试解题,但似乎什么也没有
这是我的代码,但不起作用:
class MyRedirectView(RedirectView): def head(self, *args, **kwargs): response = HttpResponse() response['X-Robots-Tag'] = 'noindex' print('TEST') return response
这里所做的是重写head方法。它只在对您的url发出HEAD类型的HTTP请求时使用。您应该重写get方法,或者更好地替代dispatch方法。在
head
get
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
这里所做的是重写
head
方法。它只在对您的url发出HEAD类型的HTTP请求时使用。您应该重写get
方法,或者更好地替代dispatch方法。在相关问题 更多 >
编程相关推荐