2015-02-02 4 views
0

일반적으로 클래스 기반 뷰와 장고에 대해 배우려고합니다. 프로젝트는 notes_project이고 그 안에는 앱 notes을 만들었습니다.django - 'function'객체에는 'resolve'속성이 없습니다.

notes_project/urls.py

from django.conf.urls import patterns, include, url 
from django.contrib import admin 
import notes 


urlpatterns = patterns('', 
    # Examples: 
    # url(r'^$', 'notes_project.views.home', name='home'), 
    # url(r'^blog/', include('blog.urls')), 
    url(r'^notes/', include('notes.urls')), 
    url(r'^grappelli/', include('grappelli.urls')), 
    url(r'^admin/', include(admin.site.urls)), 
) 

노트/urls.py

from django.conf.urls import include, patterns, url 
from .views import IndexView 


urlpatterns = patterns(r'^$/', IndexView.as_view()) 

노트/조회수 : 아래 notes 응용 프로그램에 대한이 두 가지에 대한 urls.pyviews.py입니다 .py

나는 URL http://127.0.0.1:8000/notes/에 액세스 할 때마다 10
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") 

그러나, 나는 오류가 아래 점점 계속 : patterns

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'] 

답변

0

첫 번째 인수는 패턴의 나머지 부분에 접두어로 역할을하는 문자열입니다. 또한 각 패턴은 자체적 인 튜플이어야합니다. 주 urls.py에서 올바르게 수행했지만 메모 노트에서 빠뜨린 것입니다. 그것은이어야한다 :

urlpatterns = patterns('', 
    (r'^$', IndexView.as_view()), 
) 
+0

나는 또한 함수 정의에서'self'를 놓쳤다. 이 추가,하지만, 난 여전히 얻을 : 는'notes_project.urls에 정의 된 URLconf를 사용하여, 장고 순서로,이 URL 패턴을 시도 : ^ 노트/^ $/ ^ grappelli/ ^ 관리 /'당신은했다 – Dharmit

+0

인덱스 패턴의 끝 부분에 여분의'/'가 있습니다. 이는 결코 일치 할 수 없음을 의미합니다. 내 대답을 편집했습니다. –

+0

그건 속임수 였어. 감사합니다 @ 다니엘 로스 만 – Dharmit