Python flask detect browser language, pythonflask

Source: Internet
Author: User

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-ITFor 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.