Customize HTML Django ModelForm Output

I am trying to add some inline form elements to a page using Djangos ModelForms. I need select flags tied to database models. Forms are formatted and placed in a table format, so I only need to display ModelForm without ANY surrounding HTML.

class LeagueForm(ModelForm): league = forms.ModelChoiceField(queryset=League.objects.all(), empty_label='Manual Team Entry:', required=False) class Meta: model = League exclude = ['league_name'] 

Template:

 {% if selected_sport == 1 %} <td>{{ nhl_form.as_p }}</td> {% else %} 

The problem is that I don't want paragraph tags, nor table tags, or anything at all. I need the form to sit well where I place it without distorting the surrounding HTML file.

Can someone point me in the right direction? Thanks

+4
source share
2 answers

Just refer to each field separately.

 {{ nhl_form.league }} 

only the league field will be displayed, without surroundings.

+15
source

All Articles