AlexW
AlexW

Reputation: 2591

Django - how to use a template tag within a url

I have a template tag named 'string_after' that I want to use within a URL. however I cant find anywhere what the syntax would be to use the tag within a URL?

I would use the tag as such

{% string_after type.site_type 'd' %}

which I tried to put inside the url but it is just seen as another url variable instead of the function

<li><a href="{% url 'sites:site_list' 'all' string_after type.site_type 'd' %}"> %}">{{ type.site_type }}</a></li>

Does anybody know the correct syntax?

Thanks

Upvotes: 1

Views: 83

Answers (1)

solarissmoke
solarissmoke

Reputation: 31404

You can't embed one tag inside another like that.

What you can do is save the output of one tag as a variable and then use it in the other:

{% string_after type.site_type 'd' as string_to_use %}

Then:

{% url 'sites:site_list' 'all' string_to_use %}

This assumes that string_after is a simple_tag.

Upvotes: 2

Related Questions