0

I have a django view that lists several urls on external sites.

When I render them I would like to add a few url parameters to each.

These urls are to an external system and thus not listed in my urls.py. Furthermore, some of the links have a hash '#' so it is not as easy as appending a few parameters to the end of the string.

Based on these requirements it seems the url template tag will not be a good fit. I was wondering if there is a custom filter out that to do this.

4
  • Why would you need the url tag? It would help if you could create an minimal reproducible example Commented Jun 22, 2016 at 12:21
  • 2
    It's not very clear what you are asking. The url template tag is for generating URLs that are within your own site/project. If you want to add links to external sites then why not just put them in the HTML, URL parameters and all? Commented Jun 22, 2016 at 12:23
  • This seems odd to me why would you need a thirdparty application to solve this problem. Seems like typing ?foo=bar&pop=lol is a lot less key strokes then the pip install + add_query="foo=bar" etc. Commented Jun 22, 2016 at 20:47
  • @marcusshep that's not entirely true. what about url fragments(#)? the params need to come before it. what if there are already url params? you don't need to add the '?'. I agree it's not a lot of code but there are definitely edge cases here. Commented Jun 23, 2016 at 15:00

1 Answer 1

1

You don't need Django's url tag here. The url tag is to resolve to URLs that belong to your application.

However, there is the nice django-spurl library. It allows you to handle query parameters via template tags.

An example from the documentation to add query parameters:

{% spurl base="http://example.com/?foo=bar" add_query="bar=baz" %}

<!--
will result in: http://example.com?foo=bar&bar=baz 
-->
Sign up to request clarification or add additional context in comments.

Comments

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.