Reputation: 50989
I have some Django app, which has a geolocation form, which I would like to understand how it works as an example.
I can fill form with from and to addresses and when I press Go
button it will open the following url
http://mysite/?route_from=32.71568%2C-117.16171&route_to=34.05361%2C-118.2455&auto_update=false
and it shows the route between cities.
The form is encoded with
{% block content %}
{% with action=using_next|default:"home" %}
<form method="get" action="{% url 'ui:'|add:action %}">
...
<input name="auto_update" type="hidden" value="false"/>
<button type="submit">{% if using_next %}Go!{% else %}Save{% endif %}</button>
</div>
</div>
</div>
</form>
{% endwith %}
I was wishing to make static URL to instantly open the same route and added inside with
<div class="row">
<div class="col-sm-10">
<div class="box">
<div id="predefined_01">
Example 01: <a href="{% url 'ui:'|add:action route_from='32.71568,-117.16171' route_to='34.05361,-118.2455' auto_update='false' %}">San Diego - Lon Angeles</a>
</div>
</div>
</div>
</div>
I was thinking it will fill the same arguments as a form and navigate to the same place.
Unfortunately, it swears upon render:
NoReverseMatch at /settings/ Reverse for 'tracker' with keyword arguments '{'route_from': '32.71568,-117.16171', 'route_to': '34.05361,-118.2455', 'auto_update': 'false'}' not found. 1 pattern(s) tried: ['$']
settings
is a current page.
What I did wrong and how to fix?
Upvotes: 0
Views: 26
Reputation:
Query parameters are not keyword arguments and are not part of the URL resolving.
/path
and /path?optional=1
are the same url /path
.
To create the correct url with correct query parameters use:
<a href="{% url 'ui:'|add:action %}?route_from={{'32.71568,-117.16171'|urlencode}}&route_to={{'34.05361,-118.2455'|urlencode}}&auto_update=false">link</a>
Upvotes: 1