Sometimes, we want to fix Python Django URLs TypeError: view must be a callable or a list/tuple in the case of include().
In this article, we’ll look at how to fix Python Django URLs TypeError: view must be a callable or a list/tuple in the case of include().
How to fix Python Django URLs TypeError: view must be a callable or a list/tuple in the case of include()?
To fix Python Django URLs TypeError: view must be a callable or a list/tuple in the case of include(), we can reference the view with the name
in the urlpatterns
list in urls.py and the view function.
For instance, we write
from django.conf.urls import include, url
from django.contrib.auth.views import login
from myapp.views import home, contact
urlpatterns = [
url(r'^$', home, name='home'),
url(r'^contact/$', contact, name='contact'),
url(r'^login/$', login, name='login'),
]
to assign urlpatterns
to a list that has url
objects created by calling url
with the view function as the 2nd argument and the name
of the view that’s mapped to the URL pattern as the 3rd argument.
Then the URLs will be mapped to the views in the 2nd argument.
Conclusion
To fix Python Django URLs TypeError: view must be a callable or a list/tuple in the case of include(), we can reference the view with the name
in the urlpatterns
list in urls.py and the view function.