简体   繁体   English

如何在 drf APIView 中检索 URL 片段参数?

[英]How to retrieve URL fragment parameters in drf APIView?

I have created a callback view for instagram account connection in django by inheriting the APIView class.我通过继承APIView class 在 django 中为 instagram 帐户连接创建了回调视图。

After successful connection of instagram account facebook redirects me to the InstagramConnectCallbackView and includes the response data as a URL fragment.成功连接 instagram 帐户 facebook 后将我重定向到InstagramConnectCallbackView并将响应数据包含为 URL 片段。

url: url:

http://localhost:8000/v1/instagram-connect/callback/?#access_token=EAAN....&data_access_expiration_time=1650543346&expires_in=6254&state=eyd...

But I don't know how to read the URL fragments from the request into the get method.但是我不知道如何将请求中的URL片段读取到get方法中。

callback view:回调视图:

class InstagramConnectCallbackView(APIView):
    permission_classes = (permissions.AllowAny,)
    version = settings.FACEBOOK_GRAPH_API_VERSION

    def get(self, request, format=None):
        ....

I tried the following:我尝试了以下方法:

request.get_full_path() # returns `/v1/instagram-connect/callback/`
request.query_params()  # returns `{}`

Any help will be appreciated.任何帮助将不胜感激。

You can use query_params as您可以使用query_params作为

request.query_params.get('your_key_name')

If you want default then yot can use如果你想要default ,那么你可以使用

self.request.query_params.get('your_key_name', None)

In your case you can get values like在您的情况下,您get类似的值

access_token = self.request.query_params.get('access_token', None)
data_access_expiration_time = self.request.query_params.get('data_access_expiration_time', None)
expires_in = self.request.query_params.get('expires_in', None)

and so on ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM