-
-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Firefox Character Encoding #100
Comments
The error you're encountering in Firefox is due to the character encoding not being specified for the plain text document. To resolve this issue, you can set the content_type attribute with the charset specified in the HttpResponse or TemplateView. Since you're using django-robots, you can simply extend the base view class to include the charset in the content_type. Here's a possible solution:
This should now properly set the charset for your robots.txt and resolve the error. Please let me know if you need further assistance or explanation. To fix the character encoding issue in Firefox when using django-robots, you can modify the code for serving the robots.txt file to include the appropriate character encoding. One option is to use the TemplateView class from Django's views.generic module to render the contents of the robots.txt file as a template. You can set the content_type argument to the appropriate value based on the character encoding used. Here's an example implementation:
Alternatively, you can use a lambda function to serve the robots.txt file. You can set the charset attribute of the HttpResponse object to the appropriate value based on the character encoding used. Here's an example implementation:
This code will render the robots.txt template and return an HttpResponse object with the appropriate character encoding set to UTF-8. This should resolve the character encoding issue in Firefox when using django-robots. |
Firefox console shows this error:
"The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature."
Current code:
url(r'^robots.txt/', include('robots.urls')),
Alternatives?
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"),
How do you combine include('robots.urls') with the alternatives or is it not possible?
It should probably be:
content="text/html; charset=utf-8" or "text/plain; charset=UTF8" not 'text/plain'
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
The text was updated successfully, but these errors were encountered: