Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: No module named 'app'

Django barfs with

ImportError at /store/
No module named store

But right there is the debug message there is the setting

INSTALLED_APPS = 
  ('django.contrib.auth',
  'django.contrib.contenttypes',
  'django.contrib.sessions',
  'django.contrib.sites',
  'django.contrib.messages',
  'django.contrib.staticfiles',
  'django.contrib.admin',
  'django.contrib.admindocs',
  'store')

Environment:


Request Method: GET
Request URL: http://localhost:8000/

Django Version: 1.4.5
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'store')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/home/paul/cs462/store/store/views.py" in main
  37.   return redirect(reverse('django.contrib.auth.views.login'))
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in reverse
  476.     return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix
  363.         possibilities = self.reverse_dict.getlist(lookup_view)
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in reverse_dict
  276.             self._populate()
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in _populate
  253.                     for name in pattern.reverse_dict:
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in reverse_dict
  276.             self._populate()
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in _populate
  265.                 lookups.appendlist(pattern.callback, (bits, p_pattern, pattern.default_args))
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in callback
  216.         self._callback = get_callable(self._callback_str)
File "/usr/lib/python2.7/site-packages/django/utils/functional.py" in wrapper
  27.         result = func(*args)
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in get_callable
  105.                     not module_has_submodule(import_module(parentmod), submod)):
File "/usr/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)

Exception Type: ImportError at /
Exception Value: No module named store

The shell works just fine (for what I try), but this error is displayed at every page I have. Doesn't having 'store' in the apps means that the module is imported???

EDIT: I've used Django for project many times. This was working a few hours ago. There is a blank __init__.py file in store/. Moreover, by using a print statement, I was able to determine that this gets executed (twice). urls.py and models.py also are executed (but not views.py). I have no idea what I could do to get this error.

like image 601
Paul Draper Avatar asked Mar 14 '13 08:03

Paul Draper


1 Answers

If it were not for version control, I would have never found this. As it was, it took me almost an hour to track it down.

The mistake was in store/urls.py:

urlpatterns = patterns('store.views',
    url(r'^$', 'main'),
    url(r'^new_delivery_user/$', 'new_delivery_user'),
    ...
    url(r'^event_signal/$', 'store.views.event_signal'), # problem
)

I had moved the last URL from the project url.py to this app-specific one, which used the shorthand 'store.views' for prepending each of the views.

It should have appeared:

    url(r'^event_signal/$', 'event_signal'),
like image 91
Paul Draper Avatar answered Oct 01 '22 22:10

Paul Draper