python flask detect browser language

python flask detect browser language

No problem. We won‘t show you that ad again. Why didn‘t you like it?

  • Uninteresting
  • Misleading
  • Offensive
  • Repetitive
  • Other

Oops! I didn‘t mean to do this.


         up vote-2down votefavorite

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

request.headers.get(‘languages‘)

This however returns None.

I tried whoer.net and it returned it-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 14:50

IanAuld

4,62111935

asked May 24 ‘15 at 16:46

PythonFun

285

 

                                                                                                                    

Have you tried something like print(request.headers) to see what is in there?                     – IanAuld                 May 25 ‘15 at 14:50                                                                            

add a comment |                      

2 Answers                                 2

active         oldest         votes


         up vote0down vote

You should check HTTP_ACCEPT_LANGUAGE


share|improve this answer

answered May 24 ‘15 at 16:53

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 at 1:29                                                                            

add a comment |                      

No problem. We won‘t show you that ad again. Why didn‘t you like it?

  • Uninteresting
  • Misleading
  • Offensive
  • Repetitive
  • Other

Oops! I didn‘t mean to do this.


         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 that, then check out Flask-Babel.

时间: 2024-11-07 14:48:26

python flask detect browser language的相关文章

python flask model 序列化

class DictSerializable(object): def as_dict(self,*args): result = OrderedDict() keys=args or self.__mapper__.c.keys() for key in keys: if hasattr(self,key): obj=getattr(self, key) if isinstance(obj,basestring): value=obj elif isinstance(obj,int) or i

Python.Flask.0

1. 吐槽 Python Web 框架 Flask https://blog.tonyseek.com/post/discuss-about-flask-framework/ 2. How To Structure Large Flask Applications https://www.digitalocean.com/community/tutorials/how-to-structure-large-flask-applications Python.Flask.0,布布扣,bubuko.

python flask api

使用python的Flask实现一个RESTful API服务器端[翻译] 用python+flask自己制作api(教程附源码)

在MAC OS 下配置python + Flask ,并支持pyCharm编辑器

原创咯- flask是一个micro framework ,伸缩性很强.可以部署到openshift 的PAAS里.这个框架上手非常快.喜欢的可以试试. 若实在MAC里,python已经默认安装了.10.9的系统安装的是2.7.5的版本.所以我们这里就不详细介绍python的安装啦 1. 首先安装  vurtualenv 这是一个虚拟环境,virtualenv 允许多个版本的 Python 同时存在,对应不同的项目. 它实际上并没有安装独立的 Python 副本,但是它确实提供了一种巧妙的方式来

python+flask+mongodb+whoosh实现自己的搜索引擎(一):目录

python+flask+jieba+mongodb+whoosh实现自己的搜索引擎 一.目录 二.基于python的爬虫 三.网页去燥,URL去重 四.基于mongodb的数据存储 五.基于whoosh的全文搜索 六.基于flask的web应用

Python Flask环境搭建

Python Flask环境搭建 尽管之前多次部署过Python的Flask环境,由于没有做文档输出工作,导致后面部署时每次都得重新去填之前填过的坑,为了方便自己,也为了工作效率的提升,于是自己花了一点时间重新实验并且整理出来部署的文档,包括一键部署Flask环境脚本install.sh,和Flask环境需要的扩展的安装包packages.txt! 全部贴在代码区域! 下面是一键安装脚本install.sh #! /usr/bin/bash #version v1.0 # by andy.zhu

项目实战_Python.利用Python+Flask编写一个高性能实时主动监控平台?

项目简介: 说明: 主要用于Redis实例集中化实时主动监控,后端采用Python+Flask实现,具体实现代码请阅读代码 项目思路: 项目结构: xmzoomeye-redis ├── app │   ├── conf │   │   ├── config.py │   │   ├── config.pyc │   │   ├── __init__.py │   │   ├── __init__.pyc │   │   └── rdsdata.db │   ├── __init__.py │ 

Error generating Swagger server (Python Flask) from Swagger editor

1down votefavorite http://stackoverflow.com/questions/36416679/error-generating-swagger-server-python-flask-from-swagger-editor I've used the Swagger Editor to manually generate my Swagger spec file and generated the files for a Python Flask server.

AFNetworking+Python+Flask+pyOpenSSL构建iOS HTTPS客户端&服务器端

对于HTTPS我在网上找了一堆资料看了下, 各种协议和证书已经有点晕了 最后我现有的感觉是, 在HTTP服务器上放一个证书, 在原本的HTTP访问之前客户端先检查证书是否正确 如果客户端证书检查正确, 说明对 这个服务器就是我要连接的那个server 不对, 就说明这个server是个假冒的 同样也可以在客户端放一个证书, 服务器端检查客户端传来的证书 如果服务器检查证书正确, 就说明这个客户端是我的小弟 我允许他连接进来 不对, 就说明这个客户端是"卧底", 不能放他进来 好了 不扯