我有这个代码。我不明白为什么它显示错误,我似乎没有把DoesNotExist处理程序当已经存在....并告诉我这个错误:
/ hotel / edit / hotel-riodssdfsdf-google-facebook-351 /
中的AttributeError类型对象'hotel'没有属性'DoesNoExist'
请求方法:GET请求URL: http :: 9000 / hotel / edit / hotel-riodssdfsdf-google-facebook-351 / Django 版本:1.6.2异常类型:AttributeError异常值:
类型对象'hotel'没有属性'DoesNoExist'
异常位置:更新中的views.py,第171行
LINE 171是正确的....:除了hotel.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/')
答案 0 :(得分:1)
您拼错DoesNotExist
DoesNoExist
。将其更改为:
except hotel.DoesNotExist:
答案 1 :(得分:1)
正确的是hotel.DoesNotExist不是hotel.DoesNoExiste a