Home > Software engineering >  Current parameters in url set in the next url in django
Current parameters in url set in the next url in django

Time:01-27

I have a url like this

http://127.0.0.1:8000/orders/?from=&to=&status=1

I have an button in that page to export all orders but if i have a status I need to send this as an parameter in that url to filter before export

<a href="{% url 'orders:export' %}">Export</a>

How can I send parameters to that export function

CodePudding user response:

You can simply append your query string after url as follows

<a href="{% url 'orders:export' %}?from=&to=&status=1">Export</a>

CodePudding user response:

Your need to HTML encode the string in the href so:

<a href="{% url 'orders:export' %}?from=&amp;to=&amp;status=1">Export</a>

if you want to pass values of variables to the parameters, you use the |urlencode template tag [Django-doc]:

<a href="{% url 'orders:export' %}?from={{ from|urlencode }}&amp;to={{ to|urlencode }}&amp;status={{ status|urlencode }}">Export</a>
  •  Tags:  
  • Related