BookingConfirmation()缺少1个仅关键字必需的参数:'amount'

时间:2020-03-22 01:40:43

标签: python django

我在Python和Django中相当陌生,我正在尝试使用Stripe建立旅馆预订。 我试图将数据(房间价格)从我的房间详细信息视图传递到收费视图,但是出现以下错误。

TypeError at /booking/confirm/
BookingConfirmation() missing 1 required keyword-only argument: 'amount'
Request Method:	POST
Request URL:	http://localhost:8000/booking/confirm/
Django Version:	3.0.2
Exception Type:	TypeError
Exception Value:	
BookingConfirmation() missing 1 required keyword-only argument: 'amount'
Exception Location:	C:\Users\Administrator\Desktop\hostel\env\lib\site-packages\django\core\handlers\base.py in _get_response, line 113
Python Executable:	C:\Users\Administrator\Desktop\hostel\env\Scripts\python.exe
Python Version:	3.7.3

这是我的房间详细信息视图

def RoomBookingView(request,pk):
    publishkey = settings.STRIPE_PUBLISHABLE_KEY
    if request.method == 'POST':

        if pk:
             room_id = Room.objects.get(pk = pk)
             amount = room_id.price
             student_id = request.user
             room_id.is_reserved = True,
           
             reservation = Reservation(
             room_id = room_id.id,
             student_id = student_id.id,
             
             
             )
             reservation.save()
             try:
                    room = Room.objects.get(id=pk)
                    room.is_reserved = True
                    amount = room_id.price
                    room.save()
             except BaseException:
                    pass
             
             return redirect(reverse('confirm', args=[amount]))
    context = {
        'STRIPE_PUBLISHABLE_KEY' : publishkey,   
    }
    return render(request,'room-detail.html',context)

我的收费视图

def BookingConfirmation(request,*args,amount):
     amount = args
     if request.method == 'POST':
         charge = stripe.Charge.create(
            
            currency='usd', 
            amount = amount,
            description='A Django charge',
            source=request.POST['stripeToken']
        )
     return render(request,'booking-confirm.html',{})

0 个答案:

没有答案