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

Post Reply
svishnu19
Posts: 2
Joined: 27 Jul 2019

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

Post 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
User avatar
Aisangam
Site Admin
Posts: 28
Joined: 24 Mar 2019
Location: Delhi, India
Contact:

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

Post 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 :)
Post Reply