amazingCarrotSoup amazingCarrotSoup - 6 months ago 53
Python Question

type error django include url... thing that should not be django1.11 python2.7

I am using djangos include feature in my main urls file, from my app urls file.


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

urlpatterns = [
url(r'^posts/', include('posts.urls')),

from django.conf.urls import url

from . import views #relative import to post views

urlpatterns = [
url(r'$',"views.posts_list" ), #list all posts
url(r'create/$',"views.posts_create" ),
url(r'detail/$',"views.posts_detail" ),
url(r'update/$',"views.posts_update" ),
url(r'delete/$',"views.posts_delete" ),

here is the error:

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().

I have looked at the docs on this issue:

and the source code:

and I have no idea what I am doing wrong.

Please help. Hugs kisses, and high fives

Answer Source

Django 1.10+ no longer allows you to specify views as a string (e.g. 'myapp.views.index') in your URL patterns.

So you should config your posts like this:

from django.conf.urls import url

from . import views

urlpatterns = [
    url(r'^$', views.posts_list, name='list'),
    url(r'^create/$', views.posts_create, name='create'),
    url(r'^detail/$', views.posts_detail, name='detail'),
    url(r'^update/$', views.posts_update, name='update'),
    url(r'^delete/$', views.posts_delete, name='delete'),

It is also a good practice to add name to your urls.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download