python - Django 应用程序中 robots.txt 的推荐指令是什么?

标签 python django robots.txt

目前我的 django 项目具有以下结构。

./
../ 
app1/
app2/
django_project
manage.py
media
static
secret_stuff

我的 robots.txt 看起来像这样:

User-agent: *
Allow: /
Sitemap: mysite.com/sitemaps.xml

我想知道以下事情:

  1. 我应该将哪些推荐指令添加到我的 robots.txt 文件,因为 django 文档没有提及这个主题。

  2. 如何阻止机器人访问(索引)内容 secret_stuffmysite.com/admin/ 目录?

      Disallow: /secret_stuff      (Is that okay ?)
      Disallow: /admin            (Is that okay ?)
    

最佳答案

Robots 指令与 Django 框架无关,这就是为什么您在 Django 文档中找不到任何有关它的信息。通常,您可以决定在您的网站上允许和禁止搜索哪些内容。

有多种方法可以将 robots.txt 包含到 Django 项目中。我个人使用 django-robots 应用程序,它简化了将 robots.txt 嵌入项目的方式。

没有必要在每个项目中都使用它。如果你觉得更简单,你可以自己渲染txt文件。

我的 Django 项目的简化 robots.txt 如下所示:

User-agent: *
Disallow: /*.pdf
Disallow: /*.ppt
Disallow: /*.doc
Disallow: /*.xls
Disallow: /*.txt

User-agent: Yandex
Allow: /events
Allow: /contests
Allow: /schools
Disallow: /admin
Crawl-delay: 3

User-agent: Googlebot
Allow: /events
Allow: /contests
Allow: /schools
Disallow: /admin
Crawl-delay: 3

Host: https://mysite.ru
Sitemap: https://mysite.ru/sitemap.xml

关于python - Django 应用程序中 robots.txt 的推荐指令是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42594231/

相关文章:

python - ZMQ软件和语言绑定(bind)的区别

python - Pandas 中的就地排序值到底是什么意思?

python - 由于 Windows 上安装了 Django,我无法创建项目

python - django-simple-history 从 python shell 跟踪用户

google-analytics - 禁止搜索引擎爬虫,但允许谷歌分析

seo - 隐藏特定文件夹及其子文件夹和文件?

python - python中的函数模板

python - 将 numpy 多项式拟合到噪声数据

python - 将复杂的 python 对象映射到 django 模型

robots.txt - 为什么当我在 robots.txt 中阻止目录时,它的内容仍然出现?