TypeError:在include()的情况下,视图必须是可调用的或列表/元组 [英] TypeError: view must be a callable or a list/tuple in the case of include()

查看:261
本文介绍了TypeError:在include()的情况下,视图必须是可调用的或列表/元组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是django和python的新手。在url映射到视图我收到以下错误:
TypeError:视图必须是一个可调用或列表/元组,在include()的情况下。



网址。 py代码: -

  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是module和post_home
]#是一个视图中的函数。

views.py代码: -

  from django.shortcuts import render 
from django.http import HttpResponse
#在这里创建你的意见。
#function based views

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

追溯



解决方案

在1.10中,您将无法再通过导入路径到 url(),您需要传递实际的视图功能:

  from posts.views import post_home 

urlpatterns = [
...
url(r'^ posts / $',post_home),
]


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

解决方案

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),
]        

这篇关于TypeError:在include()的情况下,视图必须是可调用的或列表/元组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆