Open martinsvoboda opened 11 years ago
Yes, I wrote the same. All works fine if run as "manage.py runserver". But if run project via uwsgi, raised following exception:
File "/home/shop/shop/settings.py", line 295, in <module>
jingo.env.install_gettext_translations(translation)
AttributeError: 'module' object has no attribute 'env'
But project running and works.
I work around this. I have gettext installation in the file of my private app jingoi18n/init.py But for correct working it needs calling of admin.autodiscover() in urls.py of project. I think it's possible move instalation code to settings.py and it will works.
I try putting initialization code in settings.py already, same exception.
It looks like that exception has to do with jingo
not being imported correctly before running jingo.env.install_gettext_translations()
. The env
object is created as an import-time side-effect of the jingo
module. (Not a great way to do it, admittedly.)
runserver
imports everything in INSTALLED_APPS
when it runs model verification, so it works then. I'm guessing uwsgi doesn't have that init step. I've seen similar things with gunicorn and Raven, where I had to add a process start up hook to get the import-time side-effects.
How are you importing jingo in settings.py?
setttings.py:
import jingo.monkey
jingo.monkey.patch()
try:
from django.utils import translation
from jingo.import env
env.install_gettext_translations(translation)
except:
pass
env
isn't a module, but monkey
is. Try replacing the second import in the try:
block with:
import jingo
jingo.env.install_gettext_translations(translation)
Just tried. Same errror:
jingo.env.install_gettext_translations(translation)
AttributeError: 'module' object has no attribute 'env'
Can anyone who ran into this try with Jingo 0.8? There are some changes (there's no jingo.env
anymore, but jingo.get_env()
will return the instance) but the upgrade shouldn't be too rough.
Hi, jingo without any extra configuration doesn't translate texts in templates. In documentation isn't any notice about this behaviour. Issue arise because jingo in default config install null translation in jinja2 enviroment (https://github.com/jbalogh/jingo/blob/master/jingo/__init__.py#L70).
For resolving issue you must install gettext translation:
Comment before
install_null_translations()
says that call is important for testing, so we should choose cautious solution. May be create some optional setting for these cases and definitely write down documentation.