Josh Farneman
Josh Farneman

Reputation: 1739

ImportError at / No module named urls

I've created a basic Django installation under a virtualenv, started a project and enabled the admin and admin docs. When I run the server I get the following error:

Request URL: http://127.0.0.1:8000/

Django Version: 1.4.1
Python Version: 2.7.2
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')
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 "/Users/farneman/Projects/project/project_env/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  101.                             request.path_info)
File "/Users/farneman/Projects/project/project_env/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
  298.             for pattern in self.url_patterns:
File "/Users/farneman/Projects/project/project_env/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns
  328.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/farneman/Projects/project/project_env/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
  323.             self._urlconf_module = import_module(self.urlconf_name)
File "/Users/farneman/Projects/project/project_env/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)

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

My urls.py file looks like:

from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'projectname.views.home', name='home'),
    # url(r'^projectname/', include('projectname.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include('admin.site.urls')),
)

And my settings.py file's Installed Apps section looks like:

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',
)

I've looked through many other posts here and elsewhere but can't find a resolution. Any idea what's going on?

Upvotes: 3

Views: 5163

Answers (1)

patsweet
patsweet

Reputation: 1558

In your settings.py file, make sure the ROOT_URLCONF is correct.

It should look something like:

ROOT_URLCONF = '<INSERT PROJECT NAME>.urls'

Judging by what you've provided, you might want to make sure it looks like:

ROOT_URLCONF = 'projectname.urls'

Upvotes: 6

Related Questions