Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django-“function”对象没有属性“resolve”_Python_Django_Django Class Based Views - Fatal编程技术网

Python django-“function”对象没有属性“resolve”

Python django-“function”对象没有属性“resolve”,python,django,django-class-based-views,Python,Django,Django Class Based Views,我正在尝试学习基于类的视图和django。该项目是notes_项目,我在其中创建了一个应用程序notes。以下是这两个应用程序的URL.py和notes应用程序的views.py: notes\u项目/url.py notes/URL.py notes/views.py 然而,每当我访问URL时,我总是会遇到以下错误: Request Method: GET Request URL: http://127.0.0.1:8000/notes/ Django Version: 1.7.4 Ex

我正在尝试学习基于类的视图和django。该项目是notes_项目,我在其中创建了一个应用程序notes。以下是这两个应用程序的URL.py和notes应用程序的views.py:

notes\u项目/url.py

notes/URL.py

notes/views.py

然而,每当我访问URL时,我总是会遇到以下错误:

Request Method: GET
Request URL:    http://127.0.0.1:8000/notes/
Django Version: 1.7.4
Exception Type: AttributeError
Exception Value:    
'function' object has no attribute 'resolve'
Exception Location: /path/notes/venv/lib/python3.4/site-packages/django/core/urlresolvers.py in resolve, line 345
Python Executable:  /path/notes/venv/bin/python
Python Version: 3.4.2
Python Path:    
['/path/notes/notes_project',
 '/path/notes/venv/lib/python3.4',
 '/path/notes/venv/lib/python3.4/plat-x86_64-linux-gnu',
 '/path/notes/venv/lib/python3.4/lib-dynload',
 '/usr/lib/python3.4',
 '/usr/lib/python3.4/plat-x86_64-linux-gnu',
 '/path/notes/venv/lib/python3.4/site-packages']
模式的第一个参数是一个字符串,它充当其余模式的前缀。此外,每个模式都需要是自己的元组。您已经在main url.py中正确地完成了这一操作,但在notes中没有完成。应该是:

urlpatterns = patterns('',
    (r'^$', IndexView.as_view()),
)
我在函数定义中也忽略了self。添加了这一点,但我仍然得到:Django使用notes_project.URL中定义的URLconf尝试了这些URL模式,顺序如下:^notes/^$/^grappelli/^admin/您的索引模式末尾有一个额外的/,这意味着它永远无法匹配。我已经编辑了我的答案。
from django.shortcuts import render
from django.http import HttpResponse
from django.views.generic import View


class IndexView(View):

    def get(request):
        return HttpResponse("Welcome to notes index")
Request Method: GET
Request URL:    http://127.0.0.1:8000/notes/
Django Version: 1.7.4
Exception Type: AttributeError
Exception Value:    
'function' object has no attribute 'resolve'
Exception Location: /path/notes/venv/lib/python3.4/site-packages/django/core/urlresolvers.py in resolve, line 345
Python Executable:  /path/notes/venv/bin/python
Python Version: 3.4.2
Python Path:    
['/path/notes/notes_project',
 '/path/notes/venv/lib/python3.4',
 '/path/notes/venv/lib/python3.4/plat-x86_64-linux-gnu',
 '/path/notes/venv/lib/python3.4/lib-dynload',
 '/usr/lib/python3.4',
 '/usr/lib/python3.4/plat-x86_64-linux-gnu',
 '/path/notes/venv/lib/python3.4/site-packages']
urlpatterns = patterns('',
    (r'^$', IndexView.as_view()),
)