我一直在研究教程,并认为我理解了MVC框架。我有三个模型,其中两个(访客,预订)填充。我可以从客人呼叫数据没问题。我试图从预订中调用数据,并在/预订时获取ViewDoesNotExist在模块视图中尝试了scheduled_dates。错误是:'module'对象没有'booked_dates'属性。
我的网址是:
from django.conf.urls.defaults import *
#from views import current_datetime, people, detail, booked_dates
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('views',
# Examples:
# url(r'^$', 'mysite.views.home', name='home'),
# url(r'^mysite/', include('mysite.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
url(r'^time/$','current_datetime'),
url(r'^mariners/$','people'),
url(r'^mariners/(?P<guest_id>\d+)/$','detail'),
url(r'^bookings/$','booked_dates'),
)
观点是:
from django.shortcuts import get_object_or_404, render_to_response
from django.http import HttpResponseRedirect, HttpResponse
from django.template import RequestContext
from guests.models import Guest, Booking, Price
import datetime
def current_datetime(request):
now = datetime.datetime.now()
html = "<html><body>It is now %s.</body></html>" % now
return render_to_response('current_datetime.html', {'current_date': now})
def people(request):
guests_all = Guest.objects.all().order_by('last_name')
return render_to_response('guests_all.html', {'guests_all': guests_all})
def detail(request, guest_id):
g = get_object_or_404(Guest, pk=guest_id)
return render_to_response('guest_detail.html', {'detail' : g})
def booked_dates(request):
dates_all = Booking.objects.all().order_by('start_date')
return render_to_response('bookings.html', {'dates_all' : dates_all})
我没有包含模型,但是Booking是正确的类名,start_date和end_date是正确的。
我无法看到这个问题的确切复制品,并尝试了很多方法来纠正它,包括一个简单的“hello world”视图,但我得到了相同的错误信息。
我必须做错事,但看不出它可能是什么。我试过在shell中调用视图,这有效。
感谢您的帮助。
答案 0 :(得分:1)
尝试将视图中的应用名称包含在视图中,而不仅仅是视图功能
url(r'^bookings/$','guests.views.booked_dates'),