22👍
The problem is with this line (“/Users/Name/Dev/tps/products/models.py”, line 127):
watson.register(Product.objects.exclude(productimage=None))
You try to reference a model at the import time. It is no longer possible in Django 1.7. Django 1.7 allows you to use your models only after all of the applications are loaded. You should move this call to the ready
callback of AppConfig
, like this:
from django.apps import AppConfig
class ProductsConfig(AppConfig):
name = 'products'
def ready(self):
Product = self.get_model('Product')
watson.register(Product.objects.exclude(productimage=None))
Then you should reference this AppConfig
in the __init__.py
of your products
app:
default_app_config = 'products.apps.ProductsConfig'
Where apps
is the name of the module where you put the config.
Relevant Django doc: https://docs.djangoproject.com/en/dev/ref/applications/
Overall, because of this change, migrating to Django 1.7 is not as easy as one would like it to be. Here are some troubleshooting tips: https://docs.djangoproject.com/en/1.7/ref/applications/#troubleshooting
16👍
I was getting this error when I updated my django project template to 1.7. One thing that changed is the wsgi.py file so that needed some updating. Here is my traceback:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/sync.py", line 93, in handle
self.handle_request(listener, req, client, addr)
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/sync.py", line 134, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/home/kpmteam/staging/deploys/20141029-115625/site/lib/django/core/handlers/wsgi.py", line 168, in __call__
self.load_middleware()
File "/home/kpmteam/staging/deploys/20141029-115625/site/lib/django/core/handlers/base.py", line 46, in load_middleware
mw_instance = mw_class()
File "/home/kpmteam/staging/deploys/20141029-115625/site/lib/django/middleware/locale.py", line 23, in __init__
for url_pattern in get_resolver(None).url_patterns:
File "/home/kpmteam/staging/deploys/20141029-115625/site/lib/django/core/urlresolvers.py", line 372, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/kpmteam/staging/deploys/20141029-115625/site/lib/django/core/urlresolvers.py", line 366, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/kpmteam/staging/site/kpm/urls.py", line 7, in <module>
admin.autodiscover()
File "/home/kpmteam/staging/deploys/20141029-115625/site/lib/django/contrib/admin/__init__.py", line 23, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/home/kpmteam/staging/deploys/20141029-115625/site/lib/django/utils/module_loading.py", line 67, in autodiscover_modules
for app_config in apps.get_app_configs():
File "/home/kpmteam/staging/deploys/20141029-115625/site/lib/django/apps/registry.py", line 137, in get_app_configs
self.check_apps_ready()
File "/home/kpmteam/staging/deploys/20141029-115625/site/lib/django/apps/registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
AppRegistryNotReady: Apps aren't loaded yet.
This is what the wsgi.py file looked like:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
And now (running Django 1.7 with gunicorn 19.1.0):
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Changing the last two lines fixed it. Note your DJANGO_SETTINGS_MODULE might be different, typically it is “project_name.settings”
14👍
I’m late to the party, but if you’re using django-registration, you’ll have to switch to django-regitration-redux.
https://pypi.python.org/pypi/django-registration-redux/
See this answer: Django-registration compatibility issue with django 1.7
- How to unit test methods inside django's class based views?
- Installing django 1.5(development version) in virtualenv
- DRF – How to handle exception on serializer create()?
- Should I use Celery or Carrot for a Django project?
- Tastypie Negation Filter
- Django and Celery – ModuleNotFoundError: No module named 'celery.task'
- What is the different between the get logger functions from celery.utils.log and logging?