Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

question from:https://stackoverflow.com/questions/65841380/tag-inside-bootstrap-button-tag-in-django-bootstrap4

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.3k views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...