TypeError: view must be a callable or a list/tuple in the case of include()

6,404 views
Skip to first unread message

ruben.ch...@gmail.com

unread,
Feb 19, 2016, 8:55:44 AM2/19/16
to Django users
Hi there. To test out django I created a Work_manager for a site, and created this for he urls.py:

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

urlpatterns = [
   # url(r'^admin/', admin.site.urls),
    url(r'^$', 'TasksManager.views.index.page'),
    url(r'^index$', 'TasksManager.views.index.page')
]

In the TasksManager/views/index.py:

# - * - Coding: utf -8 - * -
from django.http import HttpResponse
# View for index page.
def page(request):
return HttpResponse("Testing...")

Yet when I run the program: python manage.py runserver 127.0.0.1:8000 I get the response: 

Unhandled exception in thread started by <function wrapper at 0x7f4cd2aaf410>
Traceback (most recent call last):
 File "/usr/local/lib/python2.7/dist-packages/Django-1.10.dev20160212033127-py2.7.egg/django/utils/autoreload.py", line 226, in wrapper
   fn(*args, **kwargs)
 File "/usr/local/lib/python2.7/dist-packages/Django-1.10.dev20160212033127-py2.7.egg/django/core/management/commands/runserver.py", line 116, in inner_run
   self.check(display_num_errors=True)
 File "/usr/local/lib/python2.7/dist-packages/Django-1.10.dev20160212033127-py2.7.egg/django/core/management/base.py", line 366, in check
   include_deployment_checks=include_deployment_checks,
 File "/usr/local/lib/python2.7/dist-packages/Django-1.10.dev20160212033127-py2.7.egg/django/core/checks/registry.py", line 75, in run_checks
   new_errors = check(app_configs=app_configs)
 File "/usr/local/lib/python2.7/dist-packages/Django-1.10.dev20160212033127-py2.7.egg/django/core/checks/urls.py", line 13, in check_url_config
   return check_resolver(resolver)
 File "/usr/local/lib/python2.7/dist-packages/Django-1.10.dev20160212033127-py2.7.egg/django/core/checks/urls.py", line 23, in check_resolver
   for pattern in resolver.url_patterns:
 File "/usr/local/lib/python2.7/dist-packages/Django-1.10.dev20160212033127-py2.7.egg/django/utils/functional.py", line 35, in __get__
   res = instance.__dict__[self.name] = self.func(instance)
 File "/usr/local/lib/python2.7/dist-packages/Django-1.10.dev20160212033127-py2.7.egg/django/urls/resolvers.py", line 297, in url_patterns
   patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
 File "/usr/local/lib/python2.7/dist-packages/Django-1.10.dev20160212033127-py2.7.egg/django/utils/functional.py", line 35, in __get__
   res = instance.__dict__[self.name] = self.func(instance)
 File "/usr/local/lib/python2.7/dist-packages/Django-1.10.dev20160212033127-py2.7.egg/django/urls/resolvers.py", line 290, in urlconf_module
   return import_module(self.urlconf_name)
 File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
   __import__(name)
 File "/home/benedict/Work_manager/Work_manager/urls.py", line 21, in <module>
   url(r'^$', 'TasksManager.views.index.page'),
 File "/usr/local/lib/python2.7/dist-packages/Django-1.10.dev20160212033127-py2.7.egg/django/conf/urls/__init__.py", line 85, in url
   raise TypeError('view must be a callable or a list/tuple in the case of include().')
TypeError: view must be a callable or a list/tuple in the case of include().


Some help would be much appreciated.

Ruben

Tim Graham

unread,
Feb 19, 2016, 10:02:54 AM2/19/16
to Django users
You need to import your views and reference the callable as described at https://docs.djangoproject.com/en/stable/topics/http/urls/#example.

Referencing the view by string using patterns() is deprecated:
https://docs.djangoproject.com/en/stable/releases/1.8/#django-conf-urls-patterns

ruben.ch...@gmail.com

unread,
Feb 19, 2016, 3:04:56 PM2/19/16
to Django users
Many thanks Tim! Problem solved.

Best Regards,
Ruben
Reply all
Reply to author
Forward
0 new messages