Hey,
A filter would work better here if you can use one. The following should work:
Defined as:
@register.filter
def encode_url(link_text):
return link_text.replace(' ', '_')
And in template:
{% with state_url=flow.state.description|encode_url %}
<a href="{% url 'advance-flow' flow.id state_url %}">advance</a>
{% endwith %}
Aubrey
On Thu, Oct 30, 2014, at 03:23 PM, Daniel Grace wrote:
Hi,I am trying to use the url tag on some parameters, one of which needs to come from a function.For example as follows:{% with state_url=encode_url flow.state.description %}<a href="{% url 'advance-flow' flow.id state_url %}">advance</a>encode_url is defined as follows:@register.simple_tagdef encode_url(link_text):return link_text.replace(' ', '_')This causes an error on the with statement:Request Method:GETRequest URL:http://127.0.0.1:8000/list_flows/Django Version:1.7Exception Type:TemplateSyntaxErrorException Value:'with' received an invalid token: 'flow.state.description'I'm guessing that you cannot put another template tag in the "with" statement. I cannot see a way around this. Any ideas?Thanks
No comments:
Post a Comment