简体   繁体   中英

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?

添加字段后截图|bootstrap

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 %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM