python - How to customize a django form (adding multiple columns) -


currently, building form using default django template this:

class old_form(forms.form):     row_1 = forms.floatfield(label='row 1')     row_2_col_1 = forms.floatfield(label='row 2_1')     row_2_col_2 = forms.floatfield(label='row 2_2')  html = str(old_form()) 

however, add multiple columns template, , still use django forms object define parameters.

new temp. should (or can loop through variables):

def getdjtemplate():     dj_template ="""     <table>     <tr>{{ table.row_1 }}</tr>     <tr>       <td>{{ table.row_2_col_1 }}</td>       <td>{{ table.row_2_col_2 }}</td>     </tr>     """     return dj_template  djtemplate = getdjtemplate() newtmpl = template(djtemplate) 

my question how 'combine' new template , class old_form()?

thanks help!

you can customize form html using fields, as shown in documentation. doing in unusual way; have template in file instead of returning function, can still this:

from django.template import context  def getdjtemplate():     dj_template = """     <table>         {% field in form %}         <tr>{{ field }}</tr>         {% endfor %}         </table>         """     return dj_template  form = old_form() djtemplate = getdjtemplate() newtmpl = template(djtemplate) c = context({'form': form}) newtmpl.render(c) 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -