普通的网站直接把代码放在根目录就可以了
但是感觉django好像很麻烦啊~~,放根目录不行
有什么比较好的办法吗?难道这么简单的东西都要特地写个视图?那岂不是坑爹!?
PHP中文网2017-04-17 17:58:49
1. You can refer to the location of Django official website: github > djangoproject.com
2. Modify nginx configuration
location /robots.txt {
alias /path/to/static/robots.txt;
}
Use third-party library django-robots
Modify urls.py
,将 robots.txt
放到 templates
Table of Contents
# urls.py
from django.views.generic import TemplateView
url(r'^robots\.txt$', TemplateView.as_view(template_name='robots.txt', content_type='text/plain')),
Modify urls.py
,不需添加 robots.txt
file
# urls.py
from django.http import HttpResponse
url(r'^robots\.txt$', lambda r: HttpResponse('User-agent: *\nDisallow: /admin', content_type='text/plain')),