![]() |
urlencode does not work - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: urlencode does not work (/thread-24797.html) |
urlencode does not work - pycada - Mar-05-2020 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 %} RE: urlencode does not work - scidam - Mar-05-2020 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.
RE: urlencode does not work - pycada - Mar-06-2020 (Mar-05-2020, 10:35 AM)scidam Wrote: What did you expect from I folow this link : https://docs.djangoproject.com/en/3.0/ref/templates/builtins/ I would like to encode the url <a href="/theme/{{t|urlencode}}"> RE: urlencode does not work - scidam - Mar-07-2020 (Mar-06-2020, 11:19 PM)pycada Wrote: I would like to encode the urlHowever, 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 %} "> |