[英]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.