Question

I find the documentation between Flask Babel and Jinja confusing.

ubuntu@ubuntu-VirtualBox:~/workspace/rtbopsConfig/rtbDashboard3$ python run.py 
Traceback (most recent call last):
  File "run.py", line 11, in <module>
    from app import app
  File "/home/ubuntu/workspace/rtbopsConfig/rtbDashboard3/app/__init__.py", line 14, in <module>
    app.config.from_pyfile('babel.cfg')
  File "/usr/local/lib/python2.7/dist-packages/flask/config.py", line 129, in from_pyfile
    execfile(filename, d.__dict__)
  File "/home/ubuntu/workspace/rtbopsConfig/rtbDashboard3/app/babel.cfg", line 1
    [jinja2: **/templates/**.html]
           ^
SyntaxError: invalid syntax

This this per the docs.

[python: **.py]
[jinja2: **/templates/**.html]
extensions=jinja2.ext.autoescape,jinja2.ext.with_

Here is my __init__.py file

import os
from flask import Flask
from flaskext.babel import Babel
from config import basedir

app = Flask(__name__)
app.config.from_object('config')
app.config.from_pyfile('babel.cfg')
babel = Babel(app)

This now leaves me with nowhere to go. How to I resolve?

Was it helpful?

Solution

The babel.cfg file is not inteded as a Flask config file; it is meant to be used with the pybabel command line tool only:

pybabel extract -F babel.cfg -o messages.pot .

Remove the app.config.from_pyfile('babel.cfg') line from your __init__.py. The Flask example at the top of the Flask Babel documentation happens to use from_pyfile('mysettings.cfg') but your project already loads it's Flask configuration using from_object(config).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top