普通的网站直接把代码放在根目录就可以了但是感觉django好像很麻烦啊~~,放根目录不行有什么比较好的办法吗?难道这么简单的东西都要特地写个视图?那岂不是坑爹!?
学习是最好的投资!
1. Anda boleh merujuk kepada lokasi tapak web rasmi Django: github >
location /robots.txt { alias /path/to/static/robots.txt; }
dan letakkan urls.py ke dalam direktori 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')),
tanpa menambah urls.py failrobots.txt
# urls.py from django.http import HttpResponse url(r'^robots\.txt$', lambda r: HttpResponse('User-agent: *\nDisallow: /admin', content_type='text/plain')),
Kaedah 1
1. Anda boleh merujuk kepada lokasi tapak web rasmi Django: github >
2. Ubah suai konfigurasi nginxdan letakkan
Kaedah 4urls.py
ke dalam direktorirobots.txt
templates
tanpa menambah
urls.py
failrobots.txt