我是crispy表单的新手,我正在尝试使用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'),
答案 0 :(得分:1)
我认为它真的抱怨这个:
Div(css_class='panel-body',
Field('location', placeholder='Location'),
Div('site_type', title="Site Type")
),
您在关键字参数(Field
)之后传递了两个位置参数(Div
和css_class
)。
您可以通过重新安排来解决此问题:
Div(
Field('location', placeholder='Location'),
Div('site_type', title="Site Type")
css_class='panel-body',
),