Python flask detect browser language, pythonflask
Python flask detect browser languageUp vote-2down votefavorite
I need to get the browser language with Python flask. I have tried to use:
request.headers.get('languages')
This however returnsNone
.
I tried whoer.net and it returnedit-IT
For my browser language. How can I detect the browser language with Python flask?
Python flask
Share | improve this question |
Edited May 25 '15 at ianacould 4, 62111935 |
Asked May 24 '15 at PythonFun 285 |
|
Have you tried something likeprint(request.headers) To see what is in there? -Ianacould May 25 '15 |
Add a comment |2 Answers 2 active oldest votes
Up vote0down vote |
You shoshould checkHTTP_ACCEPT_LANGUAGE
Share | improve this answer |
Answered May 24 '15 at Anthony Kong 9,2851157114 |
|
|
|
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post.-Ken Y-N May 25 '15 |
Add a comment | |
Up vote0down vote
Check out Werkzeug's invalid ageaccept 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.