0

我一直在学习教程,并认为我已经理解了 MVC 框架。我有三个模型,其中两个(Guests,Bookings)被填充。我可以从客人那里调用数据没问题。我尝试从 Bookings 调用数据并在 /bookings 处获取 ViewDoesNotExist 在模块视图中尝试了预订日期。错误是:“模块”对象没有属性“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 中调用视图,这很有效。

谢谢你的帮助。

4

1 回答 1

1

尝试在视图中包含应用程序名称,而不仅仅是视图功能

url(r'^bookings/$','guests.views.booked_dates'),

于 2013-05-20T20:38:45.270 回答