Python Forum

Full Version: urlencode does not work
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I would like to encode the value of t in the url with urlencode. It doen't work. Do you have an idea why ?
thank you.

{% for t in liste_theme_key %}
                <div class="theme">
                  {% with 'accueil/img/'|add:t|add:'.png' as png_url %}
                        <a href="/theme/{{t|urlencode}}"><img class="image_theme" src="{% static png_url  %}" style="width:270px; height: 170px; margin-top:17x;"/></a>
                  {% endwith %}
                </div>
{% endfor %}
What did you expect from urlencode? Could you provide example with specific value of t and desired result after applying urlencode. Note, that urlencode can take additional argument, characters that should be skipped when encoding; by default, it is only backslash char; If you want to disable skipping characters at all, you can do by providing empty string as a parameter, e.g. {{ t|urlencode:"" }}. Hope that helps.
(Mar-05-2020, 10:35 AM)scidam Wrote: [ -> ]What did you expect from urlencode? Could you provide example with specific value of t and desired result after applying urlencode. Note, that urlencode can take additional argument, characters that should be skipped when encoding; by default, it is only backslash char; If you want to disable skipping characters at all, you can do by providing empty string as a parameter, e.g. {{ t|urlencode:"" }}. Hope that helps.


I folow this link : https://docs.djangoproject.com/en/3.0/re.../builtins/
I would like to encode the url
<a href="/theme/{{t|urlencode}}">
(Mar-06-2020, 11:19 PM)pycada Wrote: [ -> ]I would like to encode the url
However, If the entire website is built on top of Django (is controlled by Django), it would be probably better to use url-dispatching mechanizm, i.e. builtin tag url, e.g.

<a href="{% url  'suitable-view-name' t %} ">