我有這段代碼。我不明白爲什麼它表明我似乎沒有已經存在的時候把DoesNotExist處理程序錯誤....並表明我這個錯誤:奇怪的錯誤,異常值:類型對象沒有屬性'DoesNoExist'
AttributeError at /hotel/edit/hotel-riodssdfsdf-google-facebook-351/
type object 'hotel' has no attribute 'DoesNoExist'
Request Method: GET Request URL: http::9000/hotel/edit/hotel-riodssdfsdf-google-facebook-351/ Django Version: 1.6.2 Exception Type: AttributeError Exception Value:
type object 'hotel' has no attribute 'DoesNoExist'
Exception Location: views.py in update, line 171
LINE 171是正確的....:除了酒店.DoesNoExist:
if 'member_id' not in request.session:
return HttpResponseRedirect('/login/')
else:
if request.POST:
try:
hotelObject = hotel.objects.get(slug=slug)
form = UpdateHotelForm(request.POST, instance=hotelObject)
if form.is_valid():
now = datetime.datetime.now()
name = form.cleaned_data['name']
slug_name = slugify(name + ' ' + str(now.microsecond))
hotels = hotel.objects.get(
id=hotelObject.id,
publisher=request.session['member_id'])
hotels.name = name
hotels.slug = slug_name
hotels.save()
args = {}
args.update(csrf(request))
args['form'] = form
args['message'] = False
args['name'] = hotelObject.name
return HttpResponseRedirect('/hotel/edit/' + slug_name)
else:
args = {}
args.update(csrf(request))
args['form'] = form
args['message'] = True
args['name'] = hotelObject.name
return render_to_response('hotel/edit_hotel.html', args)
except hotel.DoesNoExist:
return HttpResponseRedirect('/hotel/')
else:
try:
hotelObject = hotel.objects.get(slug=slug)
form = UpdateHotelForm(request.POST, instance=hotelObject)
form = UpdateHotelForm(instance=hotelObject)
args = {}
args.update(csrf(request))
args['form'] = form
args['name'] = hotelObject.name
return render_to_response('hotel/edit_hotel.html', args)
except hotel.DoesNoExist:
return HttpResponseRedirect('/hotel/')
其中'hotel.DoesNoExist'定義? – mhlester
難道你不是指的DoesNotExist而不是DoesNoExist? – kirbuchi
它與問題無關,但您應該在CamelCase中命名您的Django模型(即「酒店」而不是「酒店」)。 –