build_attrs()获得了意外的关键字参数“类型”

时间:2018-09-02 11:23:58

标签: python django paypal

我正在使用django框架,并尝试集成Paypal付款网关。但是我收到这个错误

build_attrs() got an unexpected keyword argument 'type'

Django版本:1.11.11
Python版本:3.6.3
异常值:build_attrs()获得了意外的关键字参数'type'
例外位置:/home/iuser/anaconda3/lib/python3.6/site-packages/paypal/standard/widgets.py,位于第35行,

from django import forms
try:
    from django.forms.utils import flatatt # Django 1.7 and later
except ImportError:
    from django.forms.util import flatatt # earlier

from django.utils.safestring import mark_safe
from django.utils.encoding import force_text


class ValueHiddenInput(forms.HiddenInput):
    """
    Widget that renders only if it has a value.
    Used to remove unused fields from PayPal buttons.
    """

    def render(self, name, value, attrs=None):
        if value is None:
            return u''
        else:
            return super(ValueHiddenInput, self).render(name, value, attrs)


class ReservedValueHiddenInput(ValueHiddenInput):
    """
    Overrides the default name attribute of the form.
    Used for the PayPal `return` field.
    """

    def render(self, name, value, attrs=None):
        if value is None:
            value = ''
        final_attrs = self.build_attrs(attrs, type=self.input_type)
        if value != '':
            final_attrs['value'] = force_text(value)
        return mark_safe(u'<input%s />' % flatatt(final_attrs))

1 个答案:

答案 0 :(得分:2)

中,build_attrs函数已按照release notes [Django-doc]中的指定进行了更改:

  

私有API Widget.build_attrs()的签名已从extra_attrs=None, **kwargs更改为base_attrs, extra_attrs=None

您需要将通话更改为:

class ReservedValueHiddenInput(ValueHiddenInput):
    """
    Overrides the default name attribute of the form.
    Used for the PayPal `return` field.
    """

    def render(self, name, value, attrs=None):
        if value is None:
            value = ''
        final_attrs = self.build_attrs(attrs, {'type': self.input_type})
        if value != '':
            final_attrs['value'] = force_text(value)
        return mark_safe(u'<input%s />' % flatatt(final_attrs))