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

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

bootstrap 4 - 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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...