我试图在Django中将access_token
变量从一个类传递到另一个类。这是代码:
def select(request):
code = request.REQUEST.get('code')
response = finish_authenticate_v2(client_id, client_secret, code)
access_token = str(response['access_token'])
return render_to_response(context_instance=RequestContext(request))
def final(request):
token = select(request)
access_token = token.access_token
return render_to_response(context_instance=RequestContext(request))
我收到错误:
Missing parameter. "code" is required
因为code
中的select()
是在select
网页中从网址获取的,但code
上没有final
来抓取网址。有没有办法传递code
以便我可以通过access_token
?
答案 0 :(得分:1)
了解sessions are used in django的方式,django.auth module
也可以看到一个很好的用法示例def select(request):
...
request.session['access_token'] = str(response['access_token'])
...
def final(request):
access_token = request.session['access_token']
...