I am following the tutorial in django and obtaining the following error.
Found few solutions but it didn't resolve my error. The tutorial link is this.
The error which I obtained is attached below. Please help me with this before duplicating the question. I am learning python and django services so it would help ma a lot.
ImportError at /polls/
cannot import name include
Request Method: GET
Request URL: http://localhost:8000/polls/
Django Version: 1.3.1
Exception Type: ImportError
Exception Value:
cannot import name include
Exception Location: /home/next/Desktop/MBS/python_files/progs/django_examples/mysite/../mysite/urls.py in <module>, line 3
Python Executable: /usr/bin/python
Python Version: 2.7.3
Python Path:
['/home/next/Desktop/MBS/python_files/progs/django_examples/mysite',
'/usr/local/lib/python2.7/dist-packages/PyQRCode-1.2-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/web.py-0.37-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/setuptools-22.0.0-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']
Server time: Mon, 6 Jun 2016 00:03:30 -0500
Edit 1: I will attach the urls.py of both so it would help to identify
in polls/urls.py
from django.conf.urls import url
from django.conf.urls import include
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
and mysite/urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]
Edit 2:The trace log is attached below
Environment:
Request Method: GET
Request URL: http://localhost:8000/polls/
Django Version: 1.3.1
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']
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/python2.7/dist-packages/django/core/handlers/base.py" in get_response
99. request.path_info)
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
269. for pattern in self.url_patterns:
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _get_url_patterns
298. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _get_urlconf_module
293. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/home/next/Desktop/MBS/python_files/progs/django_examples/mysite/../mysite/urls.py" in <module>
1. from django.conf.urls import include, url
Exception Type: ImportError at /polls/
Exception Value: cannot import name include
I have found the solution for the above mentioned question. The version of the django is the main cause. Updating the django version cleared the error which was raised previously.
the version before updating was 1.3 and now the version is 1.10
To update the django version,
$ sudo pip install -U Django
well you have to include include
in polls
urls
from django.conf.urls import include
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With