gpt4 book ai didi

django - “经理”对象不可调用

转载 作者:行者123 更新时间:2023-12-03 13:21:04 33 4
gpt4 key购买 nike

我一直在我的观点上得到这个错误。我无法解决,因为代码类似于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'),
)

有谁知道为什么会发生此错误,就像我之前所做的那样就可以正常工作了。如果需要,我可以发布更多代码。

最佳答案

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})

    与其他示例相同

    关于django - “经理”对象不可调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3277175/

    33 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com