简体   繁体   中英

Where do I start with Django when I have a development server running and have a GET request from API?

I'm running a Django development server instance and working with the LinkedIn API.

Right now, I have a python script that I can run that will open a new tab in the default web browser and ask the user to sign in with their LinkedIn account, much like a web app would open a popup window to ask for your credentials.

The python script has the Django dev server instance as the redirect URI, so the following message comes up when I authenticate:

[19/Jul/2013 08:24:33] "GET /?code=xxxxxxxxx&state=xxxxxxxxxxxxx HTTP/1.1" 200 1954

Right now, I have to manually copy the code into command line before receiving the proper OAuth access token to make API calls.

I want to make the authentication process automated and in a Django app to integrate with the front end I'll be building. I've read through django.http docs and I'm pretty sure I need to start by making a new app and using that in the views.py file of the app.

How do I extract the query using Django (or Python if I can still integrate this into the app) and use it properly?

You can read the parameters of the url with the Request object you have access to in your views.py.

https://docs.djangoproject.com/en/dev/ref/request-response/

def my_view(request):
  code = request.GET.get('code')
  state = request.GET.get('state')
  # do something

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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