0

Im trying to add a variable to the end of a string and am getting issues with reverse match, from what I gather the below should work

{% for type in type_links %}
<li><a href="{% url 'sites:site_list' 'all_'|add:type.id %}">{{ type.subnet_type }}</a></li>
{% endfor %}

I should have a url that has "all_1" for example in it.

however I am getting a reverse url error

Reverse for 'site_list' with arguments '('',)' not found. 1 pattern(s) tried: ['sites/site_list/(?P<display_filter>[\\w\\-]+)$']

is this correct way to add a variable to end the of the string?

EDIT: url pattern, the pattern works as I have tested it manually before trying to create the URLs dyanmically

url(r'^site_list/(?P<display_filter>[\w\-]+)$', views.site_list, name='site_list'),

Thanks

4
  • that returns "add requires 2 arguments, 1 provided" Commented Jan 8, 2018 at 10:18
  • my comment is not used add Commented Jan 8, 2018 at 10:39
  • post your url_pattern as well Commented Jan 8, 2018 at 10:53
  • Could not parse the remainder: '{{type.id}}' from ''all_'{{type.id}}' I believe that its because its now seeing those as two entries not one joined entry? Commented Jan 8, 2018 at 10:56

1 Answer 1

1

You can do

{% for type in type_links %}
<li>
    {% with type.id|stringformat:"s" as str_obj_id %}
      {% with 'all_'|add:str_obj_id as extra_param %}
        <a href="{% url 'sites:site_list' extra_param %}">{{ type.subnet_type }}</a>
      {% endwith %}
   {% endwith %} 
</li>
{% endfor %}
Sign up to request clarification or add additional context in comments.

2 Comments

im still getting Reverse for 'site_list' with arguments '('',)' not found. 1 pattern(s) tried: ['sites/site_list/(?P<display_filter>[\\w\\-]+)$']
when I put {{ type_links}} I get the data, and if I just loop the IDs it also works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.