Конвертация из Flask в Django, flask.url_for, flask.request.url
Я следую руководству Google OAuth Guide в Django на примере Flask. Но не могу понять некоторые из приведенных ниже кодов. Как именно можно преобразовать flask.url_for, flask.request.url в код Django.
# Flask code
flask.url_for('oauth2callback', _external=True)
# my Django code: just the url???
'http://localhost:8000/api/oauth2callback'
# Flask code
authorization_response = flask.request.url
# my Django code: but it would not work
authorization_response = request.url
По flask.request.url я не смог найти никакой документации, никакой информации о том, что он возвращает
state = flask.session['state']
flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
'client_secret.json',
scopes=['https://www.googleapis.com/auth/drive.metadata.readonly'],
state=state)
flow.redirect_uri = flask.url_for('oauth2callback', _external=True)
authorization_response = flask.request.url
flow.fetch_token(authorization_response=authorization_response)
# Store the credentials in the session.
# ACTION ITEM for developers:
# Store user's access and refresh tokens in your data store if
# incorporating this code into your real app.
credentials = flow.credentials
flask.session['credentials'] = {
'token': credentials.token,
'refresh_token': credentials.refresh_token,
'token_uri': credentials.token_uri,
'client_id': credentials.client_id,
'client_secret': credentials.client_secret,
'scopes': credentials.scopes}