Python Flask Detect Browser language

Source: Internet
Author: User

Python Flask Detect Browser language
Up vote-2down Votefavorite

I need to get the browser language with Python flask. I have the tried to use:

request.headers.get(‘languages‘)

This however returns None .

I tried whoer.net and it returned for it-IT my browser language. How can I detect the browser language with Python flask?

Python flask
Share|improve this question edited May 25 ' At 14:50         IanAuld         4,621 119 35         Asked at 16:46 pythonfun 5
           ;                                                                                                               
have you tried something like print (request.headers) to see what's in there?                     – IanAuld                  may "at 14:50                                                                                 
Add a Comment |
2 Answers2Active oldest votes
Up vote0down vote

You should checkHTTP_ACCEPT_LANGUAGE

Share|improve This answer answered at 16:53 Anthony Kong 9,285 c4>
           ;                                                                                                               
this does not provide a answer to the question. To critique or request clarification from an author, leave a comment below their post.                     – ken Y-N                  may "at 1:29                                                                                  
Add a Comment |
Up vote0down vote

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 this, then check out Flask-babel.

Python Flask Detect Browser language

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.