【发布时间】:2020-07-04 09:41:04
【问题描述】:
我正在为两种语言构建烧瓶网络应用程序。 我读了https://flask.palletsprojects.com/en/1.1.x/patterns/urlprocessors/#internationalized-application-urls
from flask import Flask, g
app = Flask(__name__)
@app.url_defaults
def add_language_code(endpoint, values):
if 'lang_code' in values or not g.lang_code:
return
if app.url_map.is_endpoint_expecting(endpoint, 'lang_code'):
values['lang_code'] = g.lang_code
@app.url_value_preprocessor
def pull_lang_code(endpoint, values):
g.lang_code = values.pop('lang_code', None)
@app.route('/<lang_code>/')
def index():
...
@app.route('/<lang_code>/about')
def about():
...
但是,我无法理解“价值观”的确切含义。 我也运行了代码,但它给出了以下错误。
g.lang_code = values.pop('lang_code', None)
AttributeError: 'NoneType' 对象没有属性 'pop'
你能给点建议吗?谢谢!
【问题讨论】:
标签: url flask routes internationalization