我的观点一直出现这个错误。我无法解决它,因为代码类似于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'),
)
有没有人知道为什么会发生这种错误,因为我之前做过的谈判工作得很好。如果需要,我可以发布更多代码。
答案 0 :(得分:32)
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})
与其他例子相同