1

I can't get this incantation right. I want a button that acts like a link.

I'm using django-bootstrap5, which has a nice {% bootstrap_button %} tag. But I can't figure out how to use django's {% url %} tag to supply the href value.

This clearly won't work...it won't even parse

  {% bootstrap_button button_type="link" content="Create Report" href="{% url 'report:create' %}" %}

So I tried this, but the link in the button ends up being the literal "create_url"

  {% url 'report:create' as create_url %}
  {% bootstrap_button button_type="link" content="Create Report" href="{{create_url}}" %}
<a class="btn btn-primary" href="{{create_url}}" role="button">Create Report</a>

there has to be a way to do this...

Chris Curvey
  • 9,738
  • 10
  • 48
  • 70

1 Answers1

1

Just ran into this same issue. Try adding a template variable before the button as you did:

{% url 'the-link' as the_link %}
{% bootstrap_button "The Button" button_type="link" button_class="btn-success" href=the_link %}

And then only reference the variable name without brackets.

hch112
  • 26
  • 2