Forums

"Translation infrastructure" error for Django 1.7

I'm trying to run Django 1.7 with Python 3.3 but I'm getting a variety of errors when I visit the site. I followed this page https://www.pythonanywhere.com/wiki/VirtualEnvForNewerDjango to get a virtualenv working.

  1. I created a new web app that uses Python 3.3
  2. source virtualenvwrapper.sh
  3. mkvirtualenv --python=python3.3 myenv
  4. pip install django==1.7
  5. django-admin.py startproject website

.This is my WSGI file.

activate_this = '/home/TreeTree/.virtualenvs/myenv/bin/activate_this.py'    
with open(activate_this) as f:
    code = compile(f.read(), activate_this, 'exec')
    exec(code, dict(__file__=activate_this))

import os
import sys

path = '/home/TreeTree/website'
if path not in sys.path:
    sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'website.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

I get errors like:

django.core.exceptions.AppRegistryNotReady: The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don't make non-lazy gettext calls at import time.

django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

AttributeError: 'Settings' object has no attribute 'r'

AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module'

django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

Not sure what to make of this since this is a completely fresh site. I haven't touched any code in the project. Feel free to dig into my files/error logs.

That's really weird. Everything looks like it's set up properly to me. I'll try to create a 3.3 / 1.7 virtualenved webapp in my own account and see if the same thing happens there.

Right, I can confirm that I get exactly the same effect by following the same steps. Odd. Investigating further.

So, it looks like the important one is the error

AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module'

-- the others seem to be being generated while it tries to handle that. Continuing investigations...

Got it. It looks like the correct way to create the WSGI application has changed between 1.6 and 1.7. If you replace the last two lines of your WSGI file with the following, it should work:

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

I've updated the docs to reflect this change.

Works now, thanks for the help.

Excellent, thanks for confirming!

I had a similar issue, and replacing the last two lines of the WSGI file worked. Thanks!

This solved my problem too ^_^