B
B
birdy902013-12-29 19:17:39
Django
birdy90, 2013-12-29 19:17:39

Using # character in django urls.py?

Good day.
I'm trying to set up OAuth from Yandex, the following problem arose: authorization passes, but after that there is a redirect to the page specified in the settings with a set of parameters (where there is also a token) going through the hash symbol. For example like this:

http://mysite.my/receive_token#access_token=<token>&token_type=bearer&...

In urls I am trying to accept this address:
url('^receive_token#access_token=(?P<token>.+?)&.*$', 'receive_token')

The problem is that django discards everything after this grid and tries to find the address http://mysite.my/receive_token, which, of course, it fails to do.
What am I doing wrong?
P.S. I tried to use code instead of token (it comes in a regular GET request without a lattice and is perfectly pulled out of the address), but I did not find the ability to use anything other than an authorization token in the Yandex.metrics API.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Vasiliev, 2014-12-30
@birdy90

Fragment IDs are not sent to the server. Never ever.
Too lazy to go into the RFC, but the idea is that URLs that differ only in a fragment are considered to refer to the same document (but to different parts of it), and therefore the server does not care about this.
The oauth mechanism you are trying to use is for client-side (javascript) authorization in some widgets and buttons.
For server authorization, there is another mechanism in which the token is passed differently.

M
Maxim Nikitenko, 2013-12-29
@sets88

the fact that after the lattice and the lattice itself is not discarded by janga, but by the browser

A
Ali Aliyev, 2013-12-29
@ali_aliev

You can also try putting r (raw string) before the string:

url(r'^receive_token#access_token=(?P<token>.+?)&.*$', 'receive_token')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question