您不会阻止视图文件,因为爬虫无法直接访问该文件。您需要阻止用于访问您的视图的 URL
robots.txt 文件必须放在主机的文档根目录中。它不会在其他地方工作。
If your host is www.example.com, it needs to be accessible at http://www.example.com/robots.txt
要删除您网站的目录或单个页面,您可以将 robots.txt 文件放在服务器的根目录下。创建 robots.txt 文件时,请记住以下几点: 在决定在特定主机上抓取哪些页面时,Googlebot 将遵循 robots.txt 文件中的第一条记录,用户代理以“Googlebot”开头。如果不存在这样的条目,它将服从用户代理为“ ”的第一个条目。此外,Google 通过使用星号为 robots.txt 文件标准引入了更高的灵活性。不允许的模式可能包括“ ”以匹配任何字符序列,模式可能以“$”结尾以指示名称的结尾。
To remove all pages under a particular directory (for example, listings), you'd use the following robots.txt entry:
User-agent: Googlebot
Disallow: /listings
To remove all files of a specific file type (for example, .gif), you'd use the following robots.txt entry:
User-agent: Googlebot
Disallow: /*.gif$
To remove dynamically generated pages, you'd use this robots.txt entry:
User-agent: Googlebot
Disallow: /*?
Option 2: Meta tags
Another standard, which can be more convenient for page-by-page use, involves adding a <META> tag to an HTML page to tell robots not to index the page. This standard is described at http://www.robotstxt.org/wc/exclusion.html#meta.
To prevent all robots from indexing a page on your site, you'd place the following meta tag into the <HEAD> section of your page:
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
To allow other robots to index the page on your site, preventing only Search Engine's robots from indexing the page, you'd use the following tag:
<META NAME="GOOGLEBOT" CONTENT="NOINDEX, NOFOLLOW">
To allow robots to index the page on your site but instruct them not to follow outgoing links, you'd use the following tag:
<META NAME="ROBOTS" CONTENT="NOFOLLOW">
供进一步参考
https://www.elegantthemes.com/blog/tips-tricks/how-to-create-and-configure-your-robots-txt-file