问题描述
在我的view.py;
def get_social_data(request):
author_name = request.GET.get ('author')
//做某事
return HttpResponse(json.dumps(result),content_type ='application / json')
在同一个view.py中,但在不同的功能中,我需要使用author_name。如果我再次写入author_name = request.GET.get('author')
,则返回NONE。
$ $ $ $ $ $ $ $ $ def $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
你能帮助我如何从get_social_data()将值传递给profile_export()。还是有其他方法来获取author_name?
谢谢。
如果是相同的 author
您可以将其保存在django中,然后在第二个函数的会话
中使用它。
def get_social_data(request):
author_name = request.GET.get('author')
session [' author_name'] = author_name
.....
在第二个函数中; / p>
def profile_export(request,slug):
author_name = session ['author_name']
In my view.py;
def get_social_data(request):
author_name = request.GET.get('author')
// To do something
return HttpResponse(json.dumps(result), content_type='application/json')
In the same view.py but in different function, I need to use author_name. If I again write "author_name = request.GET.get('author')"
, it returns "NONE".
def profile_export(request, slug):
author_name = request.GET.get('author') // Now NONE.
Can you help me how to pass the value to profile_export() from get_social_data(). Or is there any other way to get author_name?
Thank you.
If is the same author
you can save it in a django session
in the first function and then use it from the session
in the second function.
def get_social_data(request):
author_name = request.GET.get('author')
session['author_name'] = author_name
.....
And in the second function;
def profile_export(request, slug):
author_name = session['author_name']
这篇关于传递并使用另一种方法的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!