bootstrap`

问题描述 投票:0回答:1

How to avoid label tag being added when calling field|bootstrap. I have the below code

filter.py

import django_filters
from .models import Issue

class IssuesFilter(django_filters.FilterSet):
    summary = django_filters.CharFilter(label="Summary", lookup_expr="icontains")
    class Meta:
        model = Issue

Views.py

def index(request):
    issues = IssuesFilter(request.GET, queryset=Issue.objects.all())
    context = {
        'user': request.user,
        'message': 'LogedIn',
        'filter': issues
    }
    return render(request, 'testApp/index.html', context)

index.html

{% extends "firstPage/base.html" %}
{% load bootstrap %}
{% load render_table from django_tables2 %}
{% load crispy_forms_tags %}
{% block body %}
<form method="GET">
  <table>
  {% for field in filter.form %}
      <tr class="table table-borderless">
          <td>{{ field.label_tag }}</td>
          <td>{{ field|bootstrap }}</td>
      </tr>
  {% endfor %}
  </table>
  <button type="submit" class="btn btn-primary">Search</button>
</form>

{% endblock %}

When I add field|bootstrap I could see the label tag of the field is displayed. Is it possible to remove additional label tag from being added?

Screenshot after adding field|bootstrap

django django-templates django-filter django-crispy-forms django-bootstrap4
1个回答
0
投票

{% bootstrap_field field show_label=False %}
© www.soinside.com 2019 - 2024. All rights reserved.