2014-11-01 64 views
2

我創建了一個模型和模型。我在設置bootstrap3模板包並將crispy-forms放入installed_apps中。django脆皮形式 - 'SubWidget'對象沒有屬性'字段'

現在,如果我這樣做:

{% crispy form %} 

它顯示像

label_name 
<form.field> 
.. 
etc etc. 

的形式,但我想

label_name: <form.field> 
在HTML

如果我這樣做:

{% crispy form.fieldname %} 

我越來越:

'SubWidget' object has no attribute 'field' 

爲什麼呢?我如何才能輕鬆控制我的表單佈局?

回答

8

您可以通過使用as_crispy_field過濾器來完成此操作。

Via the official documentation

templatetags.crispy_forms_filters.as_crispy_field(field, template_pack='bootstrap')[source] 
Renders a form field like a django-crispy-forms field: 

{% load crispy_forms_tags %} 
{{ form.field|as_crispy_field }} 

或:

{{ form.field|as_crispy_field:"bootstrap" }} 
相關問題