Wednesday, September 1, 2010

Re: urlencode in Django

On Mon, Aug 30, 2010 at 10:45 PM, refreegrata <refreegrata@yahoo.com> wrote:
> now works for all characters. I don't  know why, but now finally
> works. ñ is converted to "%C3%B1", ó is converted to "%C3%B3", + to
> "%2B", ...
>
> thanks.
>
> P.D.: I hate use special characters in an url, generaly is a bad idea,
> but is necessary in my application.
> The client want to filter registers according the  name, and the name
> can have special characters, and i must to paginate the results. The
> other option is use a ghost form and javascript.
>
> Thanks.
>

The url resolver takes care of all of this magic for you. If you find
it isn't, then you aren't using it right. For instance:

<a href="{% url mmm %}var/{{ var|urlencode }}/">link</a>

This is clearly an incorrect use of a url pattern. Instead, the var
argument should be included as part of the urlpattern, and var given
as an argument to the url template tag.

<a href="{% url mmm-with-var var %}">link</a>

Do it like this, and you won't have problems. If you need to generate
a query string, use the pattern as described by Alexandre González in
the first reply.

Cheers

Tom

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment