Django:如何使用基于类的视图在模板中填充表单数据

时间:2018-03-21 17:13:05

标签: django python-3.x django-forms

我的观点如下:

class ListAndCreate(CreateView):
    model = xmpp_buddy_groups
    form_class = xmpp_buddy_groups_form
    second_form_class = sip_extension_form
    template_name = "xmpp/index.html"
    success_url = reverse_lazy('xmpp:index')

我的表格如下:

class xmpp_buddy_groups_form(forms.ModelForm):

    class Meta:
      model = xmpp_buddy_groups
      fields = ['group_name']

class sip_extension_form(forms.ModelForm):


   class Meta:
     model = SipExtension
     fields = ['sip_extension']
     widgets = {
            "sip_extension": forms.Select
           }

当我在模板中使用表单{{form.as_p}}时,我想在模板中填充sip_extension的数据。但我不知道我该怎么做。

0 个答案:

没有答案