twboatler
By:
twboatler

No module named URLs

August 4, 2017 423 views
Django Nginx Ubuntu 16.04
Traceback: 
Environment:


Request Method: GET
Request URL: http://67.205.177.49/

Django Version: 1.8.7
Python Version: 2.7.12
Installed Applications:
('polls',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')


Traceback:
File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  119.                 resolver_match = resolver.resolve(request.path_info)
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
  365.             for pattern in self.url_patterns:
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
  401.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module
  395.             self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py" in import_module
  37.     __import__(name)
File "/usr/lib/python2.7/dist-packages/gevent/builtins.py" in __import__
  93.             result = _import(*args, **kwargs)
File "/home/django/django_project/django_project/urls.py" in <module>
  20.     url(r'^', include('polls.urls')),
File "/usr/lib/python2.7/dist-packages/django/conf/urls/__init__.py" in include
  33.         urlconf_module = import_module(urlconf_module)
File "/usr/lib/python2.7/importlib/__init__.py" in import_module
  37.     __import__(name)
File "/usr/lib/python2.7/dist-packages/gevent/builtins.py" in __import__
  93.             result = _import(*args, **kwargs)
File "/home/django/django_project/polls/urls.py" in <module>
  3. from . import views
File "/usr/lib/python2.7/dist-packages/gevent/builtins.py" in __import__
  93.             result = _import(*args, **kwargs)
File "/home/django/django_project/polls/views.py" in <module>
  6. from django.urls import reverse
File "/usr/lib/python2.7/dist-packages/gevent/builtins.py" in __import__
  93.             result = _import(*args, **kwargs)

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

The very confusing part is that I can change the home/django/django_project/urls.py file to this:

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    #url(r'^', include('polls.urls')),
    url(r'^admin/', include(admin.site.urls)),
]

With my apps url file commented out and it will load the default django page, so the server seems to be working but breaks when I include my app. It is properly installed in settings.py. Also, if I run it locally in development everything works fine.

1 Answer

@twboatler

Are you following the getting started tutorial here? if no try to follow it and see if the problem still persists

Also one more thing the first url pattern should be url(r'^polls/', include('polls.urls')), not url(r'^', include('polls.urls')),

hope this helps

  • I'm loosely following that, while trying to implement my own stuff for a site I'm trying to build. That's probably what has created this problem.

    I'd like http://[ip address] to point to my home page for the polls app, which is why I did url(r'^', include('polls.urls')), as opposed to what you suggested.

    But I did try your suggestion and got the same error:

    Environment:
    
    
    Request Method: GET
    Request URL: http://67.205.177.49/polls
    
    Django Version: 1.8.7
    Python Version: 2.7.12
    Installed Applications:
    ('polls',
     'django.contrib.admin',
     'django.contrib.auth',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles')
    Installed Middleware:
    ('django.contrib.sessions.middleware.SessionMiddleware',
     'django.middleware.common.CommonMiddleware',
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
     'django.middleware.clickjacking.XFrameOptionsMiddleware',
     'django.middleware.security.SecurityMiddleware')
    
    
    Traceback:
    File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
      108.                 response = middleware_method(request)
    File "/usr/lib/python2.7/dist-packages/django/middleware/common.py" in process_request
      74.             if (not urlresolvers.is_valid_path(request.path_info, urlconf) and
    File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in is_valid_path
      646.         resolve(path, urlconf)
    File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
      521.     return get_resolver(urlconf).resolve(path)
    File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
      365.             for pattern in self.url_patterns:
    File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
      401.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
    File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module
      395.             self._urlconf_module = import_module(self.urlconf_name)
    File "/usr/lib/python2.7/importlib/__init__.py" in import_module
      37.     __import__(name)
    File "/usr/lib/python2.7/dist-packages/gevent/builtins.py" in __import__
      93.             result = _import(*args, **kwargs)
    File "/home/django/django_project/django_project/urls.py" in <module>
      20.     url(r'^polls/', include('polls.urls')),
    File "/usr/lib/python2.7/dist-packages/django/conf/urls/__init__.py" in include
      33.         urlconf_module = import_module(urlconf_module)
    File "/usr/lib/python2.7/importlib/__init__.py" in import_module
      37.     __import__(name)
    File "/usr/lib/python2.7/dist-packages/gevent/builtins.py" in __import__
      93.             result = _import(*args, **kwargs)
    File "/home/django/django_project/polls/urls.py" in <module>
      3. from . import views
    File "/usr/lib/python2.7/dist-packages/gevent/builtins.py" in __import__
      93.             result = _import(*args, **kwargs)
    File "/home/django/django_project/polls/views.py" in <module>
      6. from django.urls import reverse
    File "/usr/lib/python2.7/dist-packages/gevent/builtins.py" in __import__
      93.             result = _import(*args, **kwargs)
    
    Exception Type: ImportError at /polls
    Exception Value: No module named urls
    

    Thanks for the feedback.

Have another answer? Share your knowledge.