84669 personnes étudient
152542 personnes étudient
20005 personnes étudient
5487 personnes étudient
7821 personnes étudient
359900 personnes étudient
3350 personnes étudient
180660 personnes étudient
48569 personnes étudient
18603 personnes étudient
40936 personnes étudient
1549 personnes étudient
1183 personnes étudient
32909 personnes étudient
普通的网站直接把代码放在根目录就可以了但是感觉django好像很麻烦啊~~,放根目录不行有什么比较好的办法吗?难道这么简单的东西都要特地写个视图?那岂不是坑爹!?
学习是最好的投资!
1、可以参考 Django 官网所放位置:github > djangoproject.com
2、修改 nginx 配置
location /robots.txt { alias /path/to/static/robots.txt; }
使用第三方库 django-robots
修改urls.py,将robots.txt放到templates目录
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 配置
方法二
使用第三方库 django-robots
方法三
修改
urls.py
,将robots.txt
放到templates
目录方法四
修改
urls.py
,不需添加robots.txt
文件