Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named index

Tags:

python

django

I am getting the error Exception Value:No module named index. i have __init__.py in DjangoPhoneBook and phonebook folder. I'm newbie to django and i m following the tutorial on djangoproject website. I have googled this error but not getting any solutions.

What is cause and solution to this problem??

Environment:

Request Method: GET
Request URL: http://localhost:8000/Book/
Django Version: 1.2.3
Python Version: 2.6.6
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'phonebook',
 'django.contrib.admin']
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/pymodules/python2.6/django/core/handlers/base.py" in get_response
  91.                         request.path_info)
File "/usr/lib/pymodules/python2.6/django/core/urlresolvers.py" in resolve
  217.                     sub_match = pattern.resolve(new_path)
File "/usr/lib/pymodules/python2.6/django/core/urlresolvers.py" in resolve
  215.             for pattern in self.url_patterns:
File "/usr/lib/pymodules/python2.6/django/core/urlresolvers.py" in _get_url_patterns
  244.         patterns = getattr(self.urlconf_module, "urlpatterns",         self.urlconf_module)
File "/usr/lib/pymodules/python2.6/django/core/urlresolvers.py" in _get_urlconf_module
  239.             self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/pymodules/python2.6/django/utils/importlib.py" in import_module
  35.     __import__(name)

Exception Type: ImportError at /Book/
Exception Value: No module named index

Contents of urls.py is

from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
from DjangoPhoneBook.phonebook.views import *

urlpatterns = patterns('',
    (r'^Book/$', include('index'))
    (r'^admin/', include(admin.site.urls)),
)

and of views.py is

  from django.http import HttpResponse
  def index(request):
     return HttpResponse("This is a view page")
like image 767
Netro Avatar asked Mar 14 '26 14:03

Netro


1 Answers

Remove the include from your first line. include is the syntax for adding a separate url conf, so python is looking for a module called index.

Change it to the full python dot path to your view function.

urlpatterns = patterns('',
    (r'^Book/$', 'path.to.my.views.index'), # <-- and add a comma here
    (r'^admin/', include(admin.site.urls)),
)

edit: I notice you are importing your view functions. You can also specify the view function itself

urlpatterns = patterns('',
    (r'^Book/$', index),
    (r'^admin/', include(admin.site.urls)),
)
like image 170
Yuji 'Tomita' Tomita Avatar answered Mar 16 '26 04:03

Yuji 'Tomita' Tomita



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!