2015-04-28 31 views
0

我想我得到這個錯誤,因爲我添加了第二個關鍵字的上下文變量和Django貝寶不喜歡它。但我真的不知道說實話。 當我沒有在上下文變量中包含第二個鍵時,它會呈現沒有錯誤,只需在文檔中留下{'form':form}即可。但我真的需要模板中的「文檔」對象,不知道該怎麼做。 對不起,我沒有添加模板。我永遠無法將它們粘貼在這裏。使用Django PayPal獲取錯誤('False','買')KeyError在/

對這個問題的任何提示都非常感謝。

下面是這個視圖

def video(request, document_id): 
document = Document.objects.get(id=document_id) 

if request.user.id: 
    d1 =datetime.datetime.now().time() 
    t=d1.strftime('%y%m%d%h%m%s') 
    pp_price = str(document.price) 
    # What you want the button to do. 
    paypal_dict = { 
     "business": settings.PAYPAL_RECEIVER_EMAIL, 
     "amount": pp_price + ".00", 
     "item_number1":document_id, 
     "item_number2":request.user.id, 
     "item_name": document.name, 
     "invoice": document.name+t, 
     "notify_url": "http://blabla.com/paid/" + reverse('paypal-ipn'), 
     "return_url": "http://blabla.com/myvideos/", 
     "cancel_return": "http://blabla.com/video/"+document_id+"/", 
    } 
    form = PayPalPaymentsForm(initial=paypal_dict) 
    context = {"form": form, "document":document } 
    return render(request, "video.html", context) 
else: 
    return render_to_response('video.html',{'document': document}, 
           context_instance=RequestContext(request)) 

拋出的異常...

KeyError at /video/106/ 
('False', 'buy') 
Request Method: GET 
Request URL: http://blabla.com/video/106/ 
Django Version: 1.6.4 
Exception Type: KeyError 
Exception Value:  
('False', 'buy') 
Exception Location: /home/me/.local/lib/python2.7/site-packages/paypal/standard/forms.py in get_image, line 143 
Python Executable: /usr/local/bin/python 
Python Version: 2.7.9 
Python Path:  
['/home/me/webapps/blabla', 
'/home/me/webapps/blabla/src', 
'/home/me/webapps/blabla/lib/python2.7', 
'/home/me/lib/python2.7/pip-1.5.4-py2.7.egg', 
'/home/me/lib/python2.7', 
'/usr/local/lib/python27.zip', 
'/usr/local/lib/python2.7', 
'/usr/local/lib/python2.7/plat-linux2', 
'/usr/local/lib/python2.7/lib-tk', 
'/usr/local/lib/python2.7/lib-old', 
'/usr/local/lib/python2.7/lib-dynload', 
'/home/me/.local/lib/python2.7/site-packages', 
'/usr/local/lib/python2.7/site-packages', 
'/usr/local/lib/python2.7/site-packages/PIL'] 
Server time: Tue, 28 Apr 2015 17:19:04 +0000 
Traceback Switch to copy-and-paste view 

/home/me/.local/lib/python2.7/site-packages/django/core/handlers/base.py in get_response 
        response = wrapped_callback(request, *callback_args, **callback_kwargs) ... 
▶ Local vars 
/home/me/webapps/blabla/src/signups/views.py in video 
     return render(request, "video.html", context) ... 
▶ Local vars 
/home/me/.local/lib/python2.7/site-packages/django/shortcuts/__init__.py in render 
    return HttpResponse(loader.render_to_string(*args, **kwargs), 

回答

0

這是一個有點令人費解的錯誤的追查,但它實際上已經無關你在這裏展示的代碼。看起來您已經錯誤地設置了其中一項設置。從它的外觀,在你settings.py,您有:

PAYPAL_TEST = 'True' 

,而事實上,你應該有:

PAYPAL_TEST = True 

這個變量必須是一個布爾值,而不是字符串。

+0

謝謝。這工作! – user3250052