Flask-babel을 잠시 파고 있었고 단순한 blueprint
과 함께 url routing
을 얻을 수없는 것 같습니다. 여기서하여 청사진 views.py 파일에서url이 언어를 지정하지 않을 때 flask-babel 및 청사진을 사용하는 경로 경로 URL
app = Flask(__name__)
babel.init_app(app)
@babel.localeselector
def get_locale():
return g.get('lang_code', 'fr')
from .mod_main import mod_main as main_blueprint
app.register_blueprint(main_blueprint,url_prefix='/<lang_code>')
이
@mod_main.url_defaults
def add_language_code(endpoint, values):
values.setdefault('lang_code', g.lang_code)
@mod_main.url_value_preprocessor
def pull_lang_code(endpoint, values):
g.lang_code = values.pop('lang_code')
@mod_main.route('/', methods=['GET', 'POST'])
def index():
return render_template('main/index.html')
이만큼 완벽하게 잘 작동, 초기화 __.py 파일 __ 내 에 응용 프로그램을
을 손질 것 나는 http://localhost:5000/fr
로 이동하지만 http://localhost:5000/
(lang이 없으면)으로 이동하면 404 오류가 발생합니다. 보통 - 청사진은 lang_code를 접두어로 사용하기 때문에
처음으로 사용자가 http://localhost:5000/
(랭 포함하지 않음)으로 이동할 때 언어가 'fr'인 페이지가 표시 될 것으로 기대합니다. 그런 다음 사용자가 영어로 전환하고 http://localhost:5000/
으로 이동하면 영어로 표시되지만 프랑스어로 표시되지 않습니다. Cant는 이것을 작동시키는 것처럼 보인다! !!
당신을 :
난 그냥 여기 청사진 바벨을 구현하는 벗었 응용 프로그램을 업로드 - (내가 요청에 걸쳐 g 변수에 LANG을 저장하려고했던 것처럼 요청을 통해 값을 전송하는 세션 변수를 사용했다) ''/ ''에 대해 등록 된 경로가 없습니다. 청사진 루트는 모두 '/'로 시작합니다. –
dirn