Django Crispy 形式 - 位置参数跟随关键字参数错误

Django Crispy forms - positional argument follows keyword argument error

我是 crispy 表单的新手,我正在尝试使用 bootstrap 将一些表单字段设置为 bootstrap 面板,然后我会将一些其他字段添加到另一个面板中,依此类推。构建第一个面板时出现以下错误。

有些地方出了问题,但我不确定是什么?

Traceback:

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _legacy_get_response
  249.             response = self._get_response(request)

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  23.                 return view_func(request, *args, **kwargs)

File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  23.                 return view_func(request, *args, **kwargs)

File "/itapp/itapp/sites/views.py" in edit_site
  829.     from sites.forms import EditSiteForm

Exception Type: SyntaxError at /sites/edit/7
Exception Value: positional argument follows keyword argument (forms.py, line 53)

这是我的forms.py

class EditSiteForm(forms.ModelForm):

    class Meta:
        model = SiteData
        fields = ['location', 'site_type', 'bgp_as', 'opening_date','last_hw_refresh_date','is_live',
                    'tel','address','town','postcode',
                    'regional_manager','regional_manager_tel','assistant_manager','assistant_manager_tel' ,'duty_manager','duty_manager_tel']

    def __init__(self, *args, **kwargs):
        super(EditSiteForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.form_id = 'edit_site_form'
        self.helper.form_method = 'POST'
        self.helper.add_input(Submit('submit', 'Save', css_class='btn-primary'))
        self.helper.layout = Layout(
           Div(title='', css_class='panel panel-primary',
                Div(title='Details', css_class='panel-heading'),
                Div(css_class='panel-body',
                    Field('location', placeholder='Location'),
                    Div('site_type', title="Site Type")
                ),
            )
        )

这是它抱怨的台词

Div(title='Details', css_class='panel-heading'),

我觉得是真的在抱怨这个:

Div(css_class='panel-body',
    Field('location', placeholder='Location'),
    Div('site_type', title="Site Type")
),

您在关键字参数 (css_class) 之后传递了两个位置参数 (FieldDiv)。

您可以通过重新安排来解决此问题:

Div(
    Field('location', placeholder='Location'),
    Div('site_type', title="Site Type")
    css_class='panel-body',
),