error : need more than 1 value to unpack

58 views
Skip to first unread message

rafiee.nima

unread,
Jul 4, 2012, 4:08:11 AM7/4/12
to django...@googlegroups.com
Hi I got below error from my view which handle ajax request 

 need more than 1 value to unpack

here is my code

def add_room(request):
    context={}
    status=''
    if request.is_ajax:
        if request.POST:
            hotel_instance=Hotel.objects.get(request.POST['hotel'])
            if request.POST['id'] > 0 :
                room=HotelRoom.objects.get(id=request.POST['id'])
                room.hotel=hotel_instance
                room.number=request.POST['number']
                room.bed_count=request.POST['bed_count']
                room.ground_sleep=request.POST['ground_sleep']
                room.view=request.POST['view']
                room.reserved=request.POST['reserved']
                room.tv=request.POST['tv']
                room.phone=request.POST['phone']
                room.refrigerator=request.POST['refrigerator']
                room.air_condition=request.POST['air_condition']
                room.toilet=request.POST['toilet']
                room.creator=request.user
                room.save()
            else:
                room = HotelRoom(
                    hotel=hotel_instance,
                    number=request.POST['number'],
                    bed_count=request.POST['bed_count'],
                    ground_sleep=request.POST['ground_sleep'],
                    view=request.POST['view'],
                    reserved=request.POST['reserved'],
                    tv=request.POST['tv'],
                    phone=request.POST['phone'],
                    refrigerator=request.POST['refrigerator'],
                    air_condition=request.POST['air_condition'],
                    toilet=request.POST['toilet'],
                    creator=request.user )
                room.save()

    return HttpResponse({status:'success'}, mimetype="application/json")

rafiee.nima

unread,
Jul 4, 2012, 4:20:10 AM7/4/12
to django...@googlegroups.com
Oh 
I find out my mistake :D 


On Wednesday, July 4, 2012 12:38:11 PM UTC+4:30, rafiee.nima wrote:
Hi I got below error from my view which handle ajax request 
hotel_instance=Hotel.objects.get(id=request.POST['hotel'])

Jon Black

unread,
Jul 4, 2012, 4:33:37 AM7/4/12
to django...@googlegroups.com
You're also returning mimetype="application/json" outside of the request.is_ajax check. I doubt you want that.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/fNXaSuOjeKcJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
 

rafiee.nima

unread,
Jul 4, 2012, 7:35:46 AM7/4/12
to django...@googlegroups.com
tnx ;)
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages