Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am new to django and python. During url mapping to views i am getting following error: TypeError: view must be a callable or a list/tuple in the case of include().

Urls. py code:-

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


urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^posts/$', "posts.views.post_home"), #posts is module and post_home 
]                                              # is a function in view. 

views.py code:-

from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
#function based views

def post_home(request):
    response = "<h1>Success</h1>"
    return HttpResponse(response)

Traceback

enter image description here

like image 374
M Pabari Avatar asked Jul 15 '16 11:07

M Pabari


1 Answers

In 1.10, you can no longer pass import paths to url(), you need to pass the actual view function:

from posts.views import post_home

urlpatterns = [
    ...
    url(r'^posts/$', post_home),
]        
like image 68
knbk Avatar answered Sep 19 '22 13:09

knbk