Page 1 of 1

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

Posted: 15 Sep 2019
by svishnu19
I am getting error in django 2.2. when i define views of app in url.py then it shows error like this.
TypeError: view must be a callable or a list/tuple in the case of include().
My "urls.py" is like this:

Code: Select all

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

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^hello/', 'myapp.views.hello1', name = 'hello1'),
]
and "views.py" is like this

Code: Select all

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

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^hello/', 'myapp.views.hello1', name = 'hello1'),
]
Please help to resolve this

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

Posted: 15 Sep 2019
by Aisangam
This error is showing because you have not defined any function of views in "urls.py" so it is not able to call function.
This functionality was available before the version 1.1 of Django.
Now you can change your import and url pattern like this:
"urls.py":

Code: Select all

from django.conf.urls import url
from django.contrib import admin
from myapp import views

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^hello/', views.hello1, name = 'hello1'),
]
It will work :)