随心一记

一二三四五,上山打老鼠


  • 首页

  • 归档

  • 标签
ywcsb

ywcsb

游戏可以不玩,小说不能不看。

153 日志
3 分类
42 标签
RSS
GitHub 知乎 随心一记
Links
  • 随心一记
  • 追梦人物的
  • MSDN

Django如何添加robots.txt文件

发表于 2019-03-04 | 阅读 768 | 分类于 Python |

可以参考一下三种方法:

方法一:

  1. 参考 Django 官网所放位置:github > djangoproject.com
  2. 修改 nginx 配置
location  /robots.txt {
    alias  /path/to/static/robots.txt;
}

方法二

修改 urls.py,将 robots.txt 放到 templates 目录

# urls.py
from django.views.generic import TemplateView

url(r'^robots\.txt$', TemplateView.as_view(template_name='robots.txt', content_type='text/plain')),

方法三

修改 urls.py,不需添加 robots.txt 文件

# urls.py
from django.http import HttpResponse

url(r'^robots\.txt$', lambda r: HttpResponse('User-agent: *\nDisallow: /admin', content_type='text/plain')),
觉得不错,支持一下!
geerniya WeChat Pay

微信打赏

geerniya Alipay

支付宝打赏

# Python # Django
Windows openvpn开机自动启动
CentOS7搭建Confluence Wiki

发表评论

共 0 条评论

    暂无评论
© 2018 - 2022 ywcsb
冀ICP备17022045号-1
Supported by 腾讯云