djangodjango-templatesdjango-filterdjango-crispy-formsdjango-bootstrap4

djang-bootstrap avoid label tag being added when calling `field|bootstrap`


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


Solution

  • I know this comes very late but if anyone is dealing with the same problem you can find the answer in the documentation

    https://django-bootstrap4.readthedocs.io/en/latest/templatetags.html#bootstrap4.templatetags.bootstrap4.bootstrap_field

    {% bootstrap_field field show_label=False %}