简体   繁体   English

TypeError:“函数”对象没有来自urls.py的属性“ __getitem__”

[英]TypeError: 'function' object has no attribute '__getitem__' from urls.py

When I try to migrate (manage.py migrate) in Django, I get the following error: 当我尝试在Django中迁移(manage.py迁移)时,出现以下错误:

File "C:\Program Files\Python27\Scripts\Folder_Name\Folder_Name\urls.py", line 22, in <module>      
    url[(r'^$',ListView.as_view(queryset=ABC.objects.all(),template_name="Folder_Name/Folder_Name.html"))],
TypeError: 'function' object has no attribute '__getitem__'

Below is what I have for Folder_Name/urls.py 以下是我的Folder_Name / urls.py文件

from django.conf.urls import url, include
from django.views.generic import ListView, DetailView
from Folder_Name.models import ABC

urlpatterns = [

    url[(r'^$', ListView.as_view(queryset=IOC.objects.all(),template_name="Folder_Name/Folder_Name.html"))],

]

Any help will be appreciated. 任何帮助将不胜感激。 Thank you. 谢谢。

url patterns are not written like that. 网址格式不是这样写的。

Read more here: https://docs.djangoproject.com/en/1.10/topics/http/urls/ 在此处阅读更多信息: https : //docs.djangoproject.com/en/1.10/topics/http/urls/

Write it like this: (remove the list of url[..] ) 这样写:(删除url[..]的列表)

urlpatterns = [

    url(r'^$', ListView.as_view(queryset=IOC.objects.all(),template_name="Folder_Name/Folder_Name.html")),

]

url参数周围没有多余的方括号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:“浮动”对象在定义的函数中没有属性“ __getitem__” - TypeError: 'float' object has no attribute '__getitem__' in defined function TypeError:“ float”对象在函数中没有属性“ __getitem__” - TypeError: 'float' object has no attribute '__getitem__' in function typeerror&#39;builtin_function_or_method&#39;对象没有属性&#39;__getitem__&#39; - typeerror 'builtin_function_or_method' object has no attribute '__getitem__' 类型错误:&#39;function&#39; 对象在 python 中没有属性 &#39;__getitem__&#39; - TypeError: 'function' object has no attribute '__getitem__' in python TypeError:'builtin_function_or_method'对象没有属性'__getitem__' - TypeError: 'builtin_function_or_method' object has no attribute '__getitem__' TypeError:&#39;函数&#39;对象没有属性&#39;__getitem__&#39;; MEDIA_URL - TypeError: 'function' object has no attribute '__getitem__'; MEDIA_URL TypeError:“函数”对象没有属性“ __getitem __” / Python - TypeError: 'function' object has no attribute '__getitem__'/Python Python:TypeError:“函数”对象没有属性“ __getitem__” - Python: TypeError: 'function' object has no attribute '__getitem__' TypeError&#39;x&#39;对象没有属性&#39;__getitem__&#39; - TypeError 'x' object has no attribute '__getitem__' TypeError:“ NoneType”对象没有属性“ __getitem__” - TypeError: 'NoneType' object has no attribute '__getitem__'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM