2

Sometimes in my code I pass get parameters with URL's. One particular scenario is if the user is not logged in, but puts a URL for a page that requires login, they will be required to login first.

In that case I may have a URL such as: www.example.com/home/#/main/.

The end of the URL /#/main/ is for angular. However, in django when I do the below to get the next parameter above, I do this:

self.request.GET.get('next', self.redirect_url)

The problem is that in this case, next provides everything but the angular portion, so I get: www.example.com/home/.

Is there anyway to get the remaining portion of the URL as well?

KVISH
  • 12,923
  • 17
  • 86
  • 162

2 Answers2

1

Apparantly you can't. Django doesn't even see the anchor, its all handled on client (browser).

How to identify an anchor in a url in Django?

The way I got around this is I use jQuery to set a hidden input field to the hash location, which can be obtained like so:

window.location.hash

The hash gets submitted with the form and I can take it from there.

Community
  • 1
  • 1
KVISH
  • 12,923
  • 17
  • 86
  • 162
1

You have to urlencode the url before you add it as a parameter. Then it will turn into %23 and insn't the separator for the anchor anymore, which is handled client side only as KVISH described.

csenger
  • 26
  • 1
  • How do you url encode when the login is handled by the framework? – KVISH Aug 02 '14 at 07:55
  • If you rely on the framework to make an unauth redirect there is no way to do that. If you pass the URL in a get parameter you have to use urlencode() yourself. – csenger Aug 02 '14 at 12:42