djangobootstrap-4django-templatesdjango-bootstrap4

tag inside bootstrap_button tag in django-bootstrap4


I have a question regarding the bootstrap_button template tag of django-bootstrap4 (https://django-bootstrap4.readthedocs.io/en/latest/templatetags.html#bootstrap-button) , could it be possible to include a tag from my tags in the href, something like this :

{% bootstrap_button "Supprimer" button_type="link" href="../../delete/{{article.id}} " button_class="btn-danger" %} but {{article.id}} is not interpreted and it gives me a link to http://127.0.0.1:8000/delete/{{article.id}}

I also tried :

{% bootstrap_button "Supprimer" button_type="link" href="{% url 'delete' article.id %}" button_class="btn-danger" %}

it returns

TemplateSyntaxError at /edit/127/

Could not parse the remainder: '"{%' from '"{%'

Request Method:     GET
Request URL:    http://127.0.0.1:8000/edit/127/
Django Version:     3.0.5
Exception Type:     TemplateSyntaxError
Exception Value:    

Could not parse the remainder: '"{%' from '"{%'

but none of those syntax are not working... Could you help me to make it works ?

Man thanks


Solution

  • The simplest way would be to declare the url as a template variable first:

    {% url 'delete' article.id as delete_url %}
    {% bootstrap_button "Supprimer" button_type="link" href=delete_url button_class="btn-danger" %}