I came here for the same problem, but for a different reason:
Class.objects.get(id=1)
An ImportError exception was thrown in this code. What baffled me was that the code below performed perfectly and returned the result set as expected:
Class.objects.all()
Trace tail for get() method:
File "django/db/models/loading.py", line 197, in get_models self._populate() File "django/db/models/loading.py", line 72, in _populate self.load_app(app_name, True) File "django/db/models/loading.py", line 94, in load_app app_module = import_module(app_name) File "django/utils/importlib.py", line 35, in import_module __import__(name) ImportError: No module named myapp
Reading the code inside Django loading.py , I came to the conclusion that my settings.py had the wrong path to my application, which contains my definition of the Class model. All I needed to do was the correct path to the application, and the get() method performed perfectly.
Here is my settings.py with the corrected path:
INSTALLED_APPS = ( 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', # ... 'mywebproject.myapp',
)
All the confusion was caused by the fact that I am using Django ORM as standalone, so the namespace should have reflected this.
Lucio Paiva Sep 28 '13 at 17:55 2013-09-28 17:55
source share