Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
urlencode does not work
#1
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 %}
Reply
#2
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.
Reply
#3
(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}}">
Reply
#4
(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 %} ">
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020