美文网首页DJANGO GO GO GO
django如何添加robots.txt文件?

django如何添加robots.txt文件?

作者: MingSha | 来源:发表于2018-02-04 10:45 被阅读0次

方法一、
修改 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')),

方法三、
1、可以参考 Django 官网所放位置:github > djangoproject.com

2、修改 nginx 配置

location  /robots.txt {
    alias  /path/to/static/robots.txt;
}

相关文章

网友评论

    本文标题:django如何添加robots.txt文件?

    本文链接:https://www.haomeiwen.com/subject/wmcmzxtx.html