Reputation: 1507
I'm working through the official Django tutorial and adapting it slightly for my own needs using Django version 1.6.1, Python 2.7.6.
I'm at the point where it has me mapping URLs but I keep getting "No module named customers.urls" errors when there is very clearly a module with an aptly named file within, so I'm really at a loss as to what I'm doing wrong.
My initial thought was that I needed to import something customers-related in the root/urls.py but every combination of import resulted in roughly the same error, and the tutorial did not say to do this.
ROOT_URLCONF = 'taco.urls' (taco is the name of the project)
I'm running this using manage.py/runserver so there's no special web server trickery going on that I'm aware of. I've restarted it several times.
The apps are all properly registered, as the traceback can attest.
Any pointers as to something I'm overlooking would be appreciated!
root/urls.py:
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^customers/', include('customers.urls')),
url(r'^admin/', include(admin.site.urls)),
)
customers/urls.py:
from django.conf.urls import patterns, url;
from customers import views;
urlpatterns = ('',
url(r'^$', views.index, name='index')
);
customers/views.py:
from django.shortcuts import render
from django.http import HttpResponse;
def index(request):
return HttpResponse("Hello");
Traceback
Environment:
Request Method: GET
Request URL: http://192.168.3.208:8000/customers/
Django Version: 1.6.1
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'south',
'taco.customers',
'taco.inventory',
'taco.lookups',
'taco.orders')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
99. resolver_match = resolver.resolve(request.path_info)
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
337. for pattern in self.url_patterns:
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
365. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module
360. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
40. __import__(name)
File "/var/project/taco/taco/urls.py" in <module>
7. url(r'^customers/', include('customers.urls')),
File "/usr/lib/python2.7/dist-packages/django/conf/urls/__init__.py" in include
26. urlconf_module = import_module(urlconf_module)
File "/usr/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
40. __import__(name)
Exception Type: ImportError at /customers/
Exception Value: No module named customers.urls
Upvotes: 10
Views: 23504
Reputation: 6716
In your customers/urls.py:
Change this:
urlpatterns = ('',
url(r'^$', views.index, name='index')
);
For this:
urlpatterns = patterns('',
url(r'^$', views.index, name='index')
);
Also, make sure you have your __init__.py
file in package customers
. And that INSTALLED_APPS
is correctly filled with you app name.
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'south',
'customers',
'inventory',
'lookups',
'orders',
)
Upvotes: 7
Reputation: 4583
If taco is the name of the project check that apps are being referenced correctly so in your installed apps you may need the following:
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'south',
'customers',
'inventory',
'lookups',
'orders')
Upvotes: 0