Django URLs TypeError: "view must be a callable or a list/tuple in the case of include()."
Cause:
Starting from Django 1.10, specifying views as strings (e.g., 'myapp.views.home') in URL patterns is no longer allowed.
Solution:
Update your urls.py file to include the actual view callable:
Option 1: Import and reference views individually
<code class="python">from django.conf.urls import 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'), ]</code>
Option 2: Import the views module and reference views
<code class="python">from django.conf.urls import url from django.contrib.auth import views as auth_views from myapp import views as myapp_views urlpatterns = [ url(r'^$', myapp_views.home, name='home'), url(r'^contact/$', myapp_views.contact, name='contact'), url(r'^login/$', auth_views.login, name='login'), ]</code>
Note:
The above is the detailed content of Why am I getting a \'view must be a callable or a list/tuple in the case of include()\' error in Django URLs?. For more information, please follow other related articles on the PHP Chinese website!