Exception Value: No module named url -- on django poll tutorial

3,283 views
Skip to first unread message

goreano

unread,
Aug 8, 2013, 3:53:14 AM8/8/13
to django...@googlegroups.com
Hi,

I'm a newbie diving into django I've found a problem I've been hitting my head against for the last 2 days.

I think it is a path issue, actually I get the same error as i try to open any URL on localhost:8000

Can you please give me a hint...  I have to improve my path definition skills but I'm stuck here:

I get an error:

ImportError at /

No module named url
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 1.5
Exception Type: ImportError
Exception Value:
No module named url
Exception Location: /usr/local/lib/python2.7/dist-packages/django/utils/importlib.py in import_module, line 35
Python Executable: /usr/bin/python2.7
Python Version: 2.7.3
Python Path:
['/home/goreano/Dropbox/formacion/Python/Django/proyectos/mysite',
 '/home/goreano/.eclipse/org.eclipse.platform_3.7.0_155965261/plugins/org.python.pydev_2.7.1.2012100913/pysrc',
 '/home/goreano/Dropbox/formacion/Python/Django/proyectos/mysite',
 '/usr/local/lib/python2.7/dist-packages/ply-3.4-py2.7.egg',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PIL',
 '/usr/lib/python2.7/dist-packages/gst-0.10',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/pymodules/python2.7',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
 '/usr/lib/python2.7/dist-packages/ubuntuone-couch',
 '/usr/lib/python2.7/dist-packages/ubuntuone-installer',
 '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol',
 '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode',
 '/usr/lib/python2.7/dist-packages/django']
Server time: Thu, 8 Aug 2013 09:34:16 +0200


this is my settings file

import os

BASE_DIR = os.path.dirname(os.path.abspath(__file__))

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = ( )

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'polls',                      # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': 'django',
        'PASSWORD': 'password',
        'HOST': '',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.
    }
}

ALLOWED_HOSTS = []

TIME_ZONE = 'Europe/Madrid'


LANGUAGE_CODE = 'en-us'

SITE_ID = 1

USE_I18N = True


USE_L10N = True

USE_TZ = True

MEDIA_ROOT = ''

MEDIA_URL = ''

STATIC_ROOT = ''

STATIC_URL = '/static/'

STATICFILES_DIRS = ()


STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)


SECRET_KEY = 'xxxxx'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'mysite.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'mysite.wsgi.application'

TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]


INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    #'django.contrib.admindocs',
    'polls'
)


LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}


#DJANGO_SETTINGS_MODULE = 'mysite.settings'






this is the site urls file

from django.contrib import admin
admin.autodiscover()

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

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'mysite.views.home', name='home'),
    # url(r'^mysite/', include('mysite.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)),
    url(r'^polls/', include('polls.url'))
)



and this the app urls file


from django.conf.urls import patterns, url

from polls import views

urlpatterns = patterns('',
    url(r'^$', views.index, name='index')
    )



Thanks!!!!!

Bill Freeman

unread,
Aug 8, 2013, 9:05:18 AM8/8/13
to django-users
Isn't there a stacktrace that goes with that error message?



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

pa xapy

unread,
Aug 8, 2013, 9:15:35 AM8/8/13
to django...@googlegroups.com
you have a typo in the urls.py

Mike Dewhirst

unread,
Aug 8, 2013, 9:20:56 AM8/8/13
to django...@googlegroups.com
On 8/08/2013 5:53pm, goreano wrote:
> Hi,
>
> I'm a newbie diving into django I've found a problem I've been hitting
> my head against for the last 2 days.
>
> I think it is a path issue, actually I get the same error as i try to
> open any URL on localhost:8000
>
> Can you please give me a hint... I have to improve my path definition
> skills but I'm stuck here:
>
> I get an error:
> /
> /
>
>
> /ImportError at //
>
> //
>
> /No module named url/

This is the clue ... see below in your settings the ROOT_URLCONF value
which is where Django looks to see if the url sent by the browser can be
recognised (via matching to a Python regular expression) and if so,
which view code to execute.

So, that ROOT_URLCONF might include other named url modules (other
whatever.py files with (url matching to view) urls you want to satisfy.

By convention ROOT_URLCONF points to urls.py in the same directory as
the settings.py file but it doesn't have to.

If you are new to Django it can be somewhat confusing understanding the
paths involved. I found it valuable to print out all the paths if DEBUG
== True. Seeing them all permanently displayed by the dev server just
kept reminding me where they were and made debugging static file
locations and template dirs etc so easy.

Hth

>
> //
> /Request Method:/ /GET/
> /Request URL:/ /http://localhost:8000//
> /Django Version:/ /1.5/
> /Exception Type:/ /ImportError/
> /Exception Value:/
>
> /No module named url/
>
> /Exception Location:/
> //usr/local/lib/python2.7/dist-packages/django/utils/importlib.py in
> import_module, line 35/
> /Python Executable:/ //usr/bin/python2.7/
> /Python Version:/ /2.7.3/
> /Python Path:/
>
> /['/home/goreano/Dropbox/formacion/Python/Django/proyectos/mysite',
> '/home/goreano/.eclipse/org.eclipse.platform_3.7.0_155965261/plugins/org.python.pydev_2.7.1.2012100913/pysrc',
> '/home/goreano/Dropbox/formacion/Python/Django/proyectos/mysite',
> '/usr/local/lib/python2.7/dist-packages/ply-3.4-py2.7.egg',
> '/usr/lib/python2.7',
> '/usr/lib/python2.7/plat-linux2',
> '/usr/lib/python2.7/lib-tk',
> '/usr/lib/python2.7/lib-old',
> '/usr/lib/python2.7/lib-dynload',
> '/usr/local/lib/python2.7/dist-packages',
> '/usr/lib/python2.7/dist-packages',
> '/usr/lib/python2.7/dist-packages/PIL',
> '/usr/lib/python2.7/dist-packages/gst-0.10',
> '/usr/lib/python2.7/dist-packages/gtk-2.0',
> '/usr/lib/pymodules/python2.7',
> '/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
> '/usr/lib/python2.7/dist-packages/ubuntuone-client',
> '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
> '/usr/lib/python2.7/dist-packages/ubuntuone-couch',
> '/usr/lib/python2.7/dist-packages/ubuntuone-installer',
> '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol',
> '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode',
> '/usr/lib/python2.7/dist-packages/django']/
>
> /Server time:/ /Thu, 8 Aug 2013 09:34:16 +0200/
>
>
>
> this is my settings file
>
> /import os
> #DJANGO_SETTINGS_MODULE = 'mysite.settings'/
>
>
>
>
>
> this is the site urls file
>
> /from django.contrib import admin
> admin.autodiscover()
>
> # Uncomment the next two lines to enable the admin:
> # from django.contrib import admin
> # admin.autodiscover()
>
> urlpatterns = patterns('',
> # Examples:
> # url(r'^$', 'mysite.views.home', name='home'),
> # url(r'^mysite/', include('mysite.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)),
> url(r'^polls/', include('polls.url'))
> )/
>
>
> and this the app urls file
>
>
> /from django.conf.urls import patterns, url
>
> from polls import views
>
> urlpatterns = patterns('',
> url(r'^$', views.index, name='index')
> )/

Mike Dewhirst

unread,
Aug 8, 2013, 9:26:42 AM8/8/13
to django...@googlegroups.com
Sorry - I didn't look past your settings ROOT_URLCONF

Nor did I see that others have responded. Please disregard mine.

Cheers

Mike

Hamdi Gdoura

unread,
Aug 8, 2013, 10:07:12 AM8/8/13
to django...@googlegroups.com
hello ,
you forgot to add the library in urls.py
from django.conf.urls import patterns, include, url
from django.conf.urls import patterns, include, url

goreano

unread,
Aug 8, 2013, 4:18:24 PM8/8/13
to django...@googlegroups.com
Here is the full error trace

Environment:


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

Django Version: 1.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',
 'polls')
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/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  103.                     resolver_match = resolver.resolve(request.path_info)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
  319.             for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
  347.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module
  342.             self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/home/amarinetto/Dropbox/formacion/Python/Django/proyectos/mysite/mysite/urls.py" in <module>
  19.     url(r'^polls/', include('polls.url'))
File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py" in include
  25.         urlconf_module = import_module(urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)

Exception Type: ImportError at /admin/

Exception Value: No module named url


goreano

unread,
Aug 8, 2013, 4:18:58 PM8/8/13
to django...@googlegroups.com
Well, what typo is it????

goreano

unread,
Aug 8, 2013, 4:19:56 PM8/8/13
to django...@googlegroups.com
Thanks, thas was a good try, im sure it is path related, THX VM

Bill Freeman

unread,
Aug 8, 2013, 6:56:11 PM8/8/13
to django-users
On Thu, Aug 8, 2013 at 4:18 PM, goreano <gor...@gmail.com> wrote:
Here is the full error trace
 
...
 
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  103.                     resolver_match = resolver.resolve(request.path_info)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
  319.             for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
  347.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module
  342.             self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/home/amarinetto/Dropbox/formacion/Python/Django/proyectos/mysite/mysite/urls.py" in <module>
  19.     url(r'^polls/', include('polls.url'))

Your root urls.py, line 19 should say:
     url(r'^polls/', include('polls.urls'))
That is, the character before the last single quote on the line should be 's'.

goreano

unread,
Aug 9, 2013, 2:31:16 AM8/9/13
to django...@googlegroups.com
HEYYYYYY K1G,   You've got it....  this is a typical case of trees not letting me see the forest....

Thanks a lot for your eagles eye ;-)

Bill Freeman

unread,
Aug 9, 2013, 12:42:49 PM8/9/13
to django-users
Stack traces help a lot.  Just follow it up from the bottom until it's back in your code.  Then you know where to concentrate.


--
Reply all
Reply to author
Forward
0 new messages