2

我可以使用 robots.txt,也可以使用自定义 Django 中间件,但我想知道这是否可以在视图级别完成。

4

1 回答 1

0

您可以使用以下代码段添加 noindex 标记:

from django.http import HttpResponse

response = HttpResponse("Text only, please.", content_type="text/plain")
response['X-Robots-Tag'] = 'noindex'
return response
于 2019-08-12T05:45:08.163 回答