Dea*_*ean 18 django django-templates django-urls django-views
我的观点不断出现此错误.我无法解决它,因为代码类似于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})
Run Code Online (Sandbox Code Playgroud)
然后我的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'),
)
Run Code Online (Sandbox Code Playgroud)
有没有人知道为什么会发生这种错误,因为我之前做过的谈判工作得很好.如果需要,我可以发布更多代码.
小智 39
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})
Run Code Online (Sandbox Code Playgroud)
试试这个:
# Create your views here.
def talksIndex(request):
latest_talk = Talk.objects.all()
return render_to_response('talks/index.html', {'latest_talk': latest_talk})
Run Code Online (Sandbox Code Playgroud)
和其他例子一样
| 归档时间: |
|
| 查看次数: |
14850 次 |
| 最近记录: |