두 개의 장고 파삭 파삭 한 모양을 동시에 사용하는 데 어려움이 있습니다. 필자는 앱에 새 데이터를 입력하는 양식과 사용자가 의견을 제공 할 수있는 부트 스트랩 모달로 표시하는 양식을 제공합니다. 아래에서는 맨손으로 기본 템플릿을 제거했습니다.두 개의 장고 파삭 파삭 한 형태 사용
나는 그룹 양식이 있습니다
class Crispy_Group_Form(forms.ModelForm):
def __init__(self, *args, **kwargs):
self.helper = FormHelper()
# self.helper.form_tag = False
self.helper.form_class = 'form-horizontal'
self.helper.layout = Layout(
Fieldset(
'New Group',
Field('name', placeholder='Group Name'),
Field('notes', placeholder='Group Notes', rows='10', css_class='input-xxlarge'),
),
FormActions(
Submit('save_changes', 'Save changes', css_class="btn-primary"),
HTML(' | '),
Submit('cancel', 'Cancel'),
)
)
self.helper.form_id = 'id-Crispy_Group_Form'
self.helper.form_method = 'post'
super(Crispy_Group_Form, self).__init__(*args, **kwargs)
class Meta:
model = Group
exclude = ['slug']
과 연락처 양식을
class Crispy_ContactForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
self.helper = FormHelper()
self.helper.form_class = 'form ajax'
self.helper.form_action = 'feedback'
self.helper.form_tag = False
self.helper.layout = Layout(
Fieldset(
'Contact Form',
Field('topic', placeholder='Topic', css_class='input-medium'),
Field('subject', placeholder='Subject', css_class='input-xlarge'),
Field('message', placeholder='Message', rows='5', css_class='input-xlarge'),
Field('sender', placeholder='Sender', css_class='input-xlarge'),
),
)
self.helper.form_id = 'id-Crispy_ContactForm'
self.helper.form_method = 'post'
super(Crispy_ContactForm, self).__init__(*args, **kwargs)
class Meta:
model = Feedback
exclude = ['creation_date']
내보기 :
def bootstrap_test(request):
return render_to_response(
"bootstrap_test.html", {
'feedback_form' : Crispy_ContactForm,
'form' : Crispy_Group_Form,
},
context_instance=RequestContext(request))
그리고 내 아주 기본적인 템플릿 :
{% load crispy_forms_tags %}
<form action="{% url feedback %}" method="post" id="id-Crispy_ContactForm" class="form">
{% crispy feedback_form %}
</form>
{% crispy form %}
피드백 _ 폼이 두 번 표시됩니다. 마치 두 양식이 같은 양식입니다. 템플릿에서 feedback_form을 삭제하면 그룹 양식이 표시됩니다. 두 가지를 재정렬하면 {% crispy form %}이 (가) feedback_from보다 위에 있으므로 두 형식이 올바르게 표시됩니다.
I read the documentation 그러나 작동하는 방법을 찾을 수 없습니다.
왜 이런 일이 일어나고 올바르게 표시 되려면 조정해야합니까?
django-crispy-forms 1.2.0에서이 문제를 해결했습니다. –