2010-07-18 38 views
9

我不斷收到我的看法這個錯誤。我無法解決這個問題,因爲代碼與djangos教程類似,只是更改了對象名稱。這裏是我的views.py代碼:'經理'對象不可調用

from django.http import HttpResponse   
from django.template import Context, loader 
from django.shortcuts import render_to_response 
from astonomyStuff.attendance.models import Member 
from astonomyStuff.attendance.models import Non_Member 
from astonomyStuff.attendance.models import Talk 
from astonomyStuff.attendance.models import Event_Attendance  


# Create your views here.  
def talksIndex(request): 
latest_talk = Talk.objects().all() 
return render_to_response('talks/index.html', {'latest_talk': latest_talk}) 

def viewMembers(request): 
members_List = Member.objects().all() 
return render_to_response('members/index.html', {'members_List': members_List}) 

然後我urls.py是這樣的:

urlpatterns = patterns('', 
# Example: 
# (r'^astonomyStuff/', include('astonomyStuff.foo.urls')), 

# Uncomment the admin/doc line below and add 'django.contrib.admindocs' 
# to INSTALLED_APPS to enable admin documentation: 
# (r'^admin/doc/', include('django.contrib.admindocs.urls')), 

# Uncomment the next line to enable the admin: 
(r'^admin/', include(admin.site.urls)), 
(r'^attendance/$', 'astonomyStuff.attendance.views.talksIndex'), 
(r'^members/$', 'astonomyStuff.attendance.views.viewMembers'), 
) 

有沒有人有任何想法,爲什麼這個錯誤發生的事情,因爲我沒有更早有談判工作得很好。如果需要,我可以發佈更多代碼。

回答

22

objects不可調用(屬性)。

  • Talk.objects() - >不會工作

  • Talk.objects - >工作

因此,而不是試圖這樣稱呼它:

# Create your views here.  
def talksIndex(request): 
    latest_talk = Talk.objects().all() 
    return render_to_response('talks/index.html', {'latest_talk': latest_talk}) 

試試這個:

# Create your views here.  
def talksIndex(request): 
    latest_talk = Talk.objects.all() 
    return render_to_response('talks/index.html', {'latest_talk': latest_talk}) 

而同樣與其他例子

+0

你有什麼改變? – Dean 2010-07-18 20:48:34

+7

'Talk.objects()。all()'到'Talk.objects.all()' – sdolan 2010-07-18 20:50:21

+1

謝謝你看不到變化:) – Dean 2010-07-18 20:52:58