0

Here I have Url http://127.0.0.1:8000/accounts/google/login/callback/#access_token=ya29.a0AVA9y1tO4d94lkiHbIT2qjh89k0TNGXFMJ_6XzdHXvxLrsLbphuMaBmEvUHCSX8XWq5L3dqQ88ULG9Vsw1llmYi24DpbFamGcoW4KPZP-9y2ynPBJMqmuFdazz7t9KEp5qrdkVwvaCgYKATASAQASFQE65dr8nbFmeih28Lvt_Q68CBXhiQ0163

I want to get value of access_token and return that token as response mention below but don't know the way to get query_parameter after hash(#)

{
"token":'ya29.a0AVA9y1tO4d94lkiHbIT2qjh89k0TNGXFMJ_6XzdHXvxLrsLbphuMaBmEvUHCSX8XWq5L3dqQ88ULG9Vsw1llmYi24DpbFamGcoW4KPZP-9y2ynPBJMqmuFdazz7t9KEp5qrdkVwvaCgYKATASAQASFQE65dr8nbFmeih28Lvt_Q68CBXhiQ0163'
}

in urls.py

from user.views import GoogleRedirect
 path('accounts/google/login/callback/', GoogleRedirect.as_view())


in views.py

class GoogleRedirect(APIView):
    def get(self, request):
        return Response("success")

  • 2
    The fragment is *not* send to the server... – Willem Van Onsem Aug 26 '22 at 09:42
  • 1
    Does this answer your question? [Is the anchor part of a URL being sent to a web server?](https://stackoverflow.com/questions/3067491/is-the-anchor-part-of-a-url-being-sent-to-a-web-server) – luk2302 Aug 26 '22 at 09:46

1 Answers1

0

I don't know is this a good idea but if you really want to do this:

  $.get(`{% url "grv" %}${window.location.hash.slice(1)}`, function(data, status){
    console.log('done')
  });
// be sure that URL has a slash at the end (grv)

urls.py

from user.views import GoogleRedirect
...
 path('accounts/google/login/callback/<str:token>', GoogleRedirect.as_view(), name="grv")
...

views.py

class GoogleRedirect(APIView):
    def get(self, request):
        return JsonResponse({"token" : self.kwargs['token']})
enes islam
  • 1,054
  • 4
  • 12