简体   繁体   中英

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

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

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