Firefox错误: 未声明纯文本文档的字符编码。如果文档包含来自US-ASCII范围之外的字符,则在某些浏览器配置中,文档将呈现乱码。需要在传输协议中声明文件的字符编码,或者文件需要使用字节顺序标记作为编码签名。
使用https://django-robots.readthedocs.io/en/latest/
可能应该是:
content =“ text / html; charset = utf-8”或“ text / plain; charset = UTF8”不是'text / plain'
当前代码:
url(r'^robots\.txt/', include('robots.urls')),
备择方案?
path('robots.txt', TemplateView.as_view(template_name="robots.txt", content_type='text/plain')),
url(r'^robots.txt', lambda x: HttpResponse("User-Agent: *\nDisallow:", content_type="text/plain"), name="robots_file"),
您如何将include('robots.urls')与替代方法结合在一起,还是不可能?
curl -s -D - 127.0.0.1:8000/robots.txt/
HTTP/1.1 200 OK
Date: Tue, 14 Apr 2020 01:05:52 GMT
Server: WSGIServer/0.2 CPython/3.7.3
Content-Type: text/plain