Why redirects to foo.com/?next=/some/folder show up as foo.com/?next=%2Fsome%2Ffolder in browser? (i.e. how remove the %2F's? )

13 views
Skip to first unread message

Chris Seberino

unread,
Apr 23, 2016, 2:47:21 PM4/23/16
to Django users
Why redirects to foo.com/?next=/some/folder show up as foo.com/?next=%2Fsome%2Ffolder in browser?  (i.e. how remove the %2F's? )

Is there a function I can call on URLs built in a view to avoid that?

cs

François Schiettecatte

unread,
Apr 23, 2016, 3:47:58 PM4/23/16
to django...@googlegroups.com
Because the slashes are escaped, this is normal as they are a parameter and not part of the path itself.

François
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/137f689f-306d-4528-82cd-03413b747f2c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Chris Seberino

unread,
Apr 23, 2016, 5:38:15 PM4/23/16
to Django users


On Saturday, April 23, 2016 at 2:47:58 PM UTC-5, François Schiettecatte wrote:
Because the slashes are escaped, this is normal as they are a parameter and not part of the path itself.

Why URLs created by Django show /'s instead of %2F's?  The Django code knows how to
fix the appearance?!

The escaped version only appears on handmade URLs created in a view and used
for a redirect?  Somehow I'm omitting some magic Django code uses. 

Stephen J. Butler

unread,
Apr 23, 2016, 6:08:47 PM4/23/16
to django...@googlegroups.com
URLs have different parts or components. The different parts use different escaping rules.


foo.com: uses DNS escaping rules

/: uses path escaping rules, which allows / as a path separator

next=%2Fsome%2Ffolder: uses query parameter escaping rules, which does not allow "/"

Stuff after a "?" but before a "#" are query parameters, and it follows different escaping rules than the path part.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Chris Seberino

unread,
Apr 23, 2016, 7:19:51 PM4/23/16
to Django users
But I still don't see why sometimes the slash is escaped then sometimes it isn't. I've seen both ways for query parameters.... The ugly Escape version shows up when I have handmade URLs but not when Django creates the next URL itself like for logging in

Stephen J. Butler

unread,
Apr 23, 2016, 8:50:21 PM4/23/16
to django...@googlegroups.com
You mean on the standard login form? The hidden "next" form value? That value isn't part of a URL so it isn't URL escaped. It's part of the HTML attribute value, so it is HTML attribute escaped.

On Sat, Apr 23, 2016 at 6:19 PM, Chris Seberino <cseb...@gmail.com> wrote:
But I still don't see why sometimes the slash is escaped then sometimes it isn't. I've seen both ways for query parameters.... The ugly Escape version shows up when I have handmade URLs but not when Django creates the next URL itself like for logging in
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Chris Seberino

unread,
Apr 23, 2016, 9:47:15 PM4/23/16
to Django users

Sorry the culprit that is escaping slashes is urlencode not django....

if you do urllib.parse.urlencode( {"next" : "/a/b/c"} ) is python3 you'll see lots of %2F's in the output..

I want to get rid of those if that's not a problem
Reply all
Reply to author
Forward
0 new messages