- Author:
- epicserve
- Posted:
- November 16, 2009
- Language:
- Python
- Version:
- 1.1
- Score:
- 1 (after 1 ratings)
This is a hack to get HTML 5 to work for Firefox 2. It Sends the xhtml content-type to all Gecko based browsers where version is less than 1.9, or "rv:1.9pre" or "rv:1.9a" or "rv:1.9bx" where x is less than 5. I created this hack based on the information I found on this site, http://html5doctor.com/how-to-get-html5-working-in-ie-and-firefox-2/.
Just put this code in one of your middleware files (i.e. mysite/middleware.py) and then add it in your MIDDLEWARE_CLASSES in your settings.py.
Example:
MIDDLEWARE_CLASSES = (
...
'mysite.middleware.HTML5Firefox2Hack',
...
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | class HTML5Firefox2Hack(object):
"""This is a hack to get HTML 5 to work for Firefox 2. It Sends the xhtml
content-type to all Gecko based browsers where version is less than 1.9,
or "rv:1.9pre" or "rv:1.9a" or "rv:1.9bx" where x is less than 5. I
created this hack based on the information I found on this site,
http://html5doctor.com/how-to-get-html5-working-in-ie-and-firefox-2/."""
def process_response(self, request, response):
status_code = getattr(response, "status_code", None)
meta = getattr(request, "META", None)
user_agent = meta.get('HTTP_USER_AGENT', '')
import re
m = re.search('rv:1\.(([1-8]|9pre|9a|9b[0-4])\.[0-9.]+).*Gecko', user_agent)
if m:
import htmlentitydefs
response['Content-Type']='application/xhtml+xml; charset=utf-8'
for i in htmlentitydefs.name2codepoint.items():
response.content = response.content.replace('&%s;' % i[0], '&#%s;' % i[1])
return response
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 3 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Please login first before commenting.