2016-04-14 32 views
-1

bazı css benim basit django başvuru formunu paketliyordum oluşturulur ve benim form iki kez (Resim aşağıda) Ben tamsayıMaksimumDeger görebileceğiniz gibi bir tablo şeklinde istiyorum enter image description hereDjango formu iki kez

oluşturuluyor fark Aşağıda kodu açık bir şekilde tabloyu bir tabloya sardım. Yine de form, tablonun üstünde ve sonra yine tabloda görülmektedir. Benim kod tekrar kontrol var ama cant sorunu

İlgili Kod ne olduğunu anlamaya görünüyor - Form oluşturuluyor şablon

<a href="/ad_accounts"> All Accounts </a> 
<br /> 
<table class="table table-bordered table-striped"> 
    <form action="." method="POST">{% csrf_token %} 
    <thead> 
     <th>Attribute</th> 
     <th>Value</th> 
    </thead> 
    <tr> 
     <td>Title</td> 
     <td> 
      {{ form.title }} 
     </td> 
    </tr> 
    <tr> 
     <td>Objective</td> 
     <td><select class="select2_single form-control" tabindex="-1"> 
      <option value={{ form.objective }}</option> 
       </select></td> 
    </tr> 
    {{ form.as_p }} 
    <tr> 
     <td><input class="btn btn-success" type="submit" value="Submit"/></td> 
    </tr> 
    </form> 

forms.py

from django import forms 

class CampaignForm(forms.Form): 
    """ Form for creating new Campaign """ 

    def __init__(self, *args, **kwargs): 
     objectives = kwargs.get('objectives') 
     if objectives: 
      kwargs.pop('objectives') 
     else: 
      objectives = list() 
     super(CampaignForm, self).__init__(*args, **kwargs) 
     self.fields['title'] = forms.CharField(max_length=50) 
     self.fields['objective'] = forms.ChoiceField(choices=objectives) 

cevap

4

{{ form.as_p }}, form oluşturma biçiminde oluşturulmuş django'dur. Aynı şeyi manuel olarak da yapıyordunuz, bu yüzden gereksiz olabilir.

render form in template ile ilgili django dokümanına bakın.

+0

d'oh! Yardım için teşekkürler – newkid101