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?

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

How do you url encode when the login is handled by the framework?
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.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.