I need to get the browser language with Python flask. I have tried to use:
request.headers.get('languages')
This however returns None.
None
I tried whoer.net and it returned it-IT for my browser language. How can I detect the browser language with Python flask ?
it-IT
print(request.headers)
You should check HTTP_ACCEPT_LANGUAGE
HTTP_ACCEPT_LANGUAGE
Check out Werkzeug's LanguageAccept data structure, or just try something like this to get a best match:
supported_languages = ["en", "nl", "it"] lang = request.accept_languages.best_match(supported_languages)
If you need more than that, then check out Flask-Babel.
print(request.headers)
to see what is in there? – IanAuld May 25 '15 at 14:50