如何在django视图中执行api调用,前提是调用了指向该视图的模板coressplanding



hi我试图为我的应用程序获取访问令牌,但在我的"profile_token";django视图因为我只想在调用了指向该视图的模板核心时执行调用,否则它会不断破坏服务器,因为用户应该首先登录ebay,然后我可以调用

谢谢你的帮助这是代码的示例

api = Connection(config_file='ebay.yaml', domain='api.sandbox.ebay.com', debug=True)
url_vars = {'SignIn&RuName': RuName, 'SessID': SessionID}
url = 'https://signin.sandbox.ebay.com/ws/eBayISAPI.dll?'
constructed_url=(url + urllib.parse.urlencode(url_vars))  
final_url=urllib.parse.unquote(constructed_url) 

def profile(request):

context={
'final_url':final_url
}

return render(request,'users/profile.html',context)

request= {
'SessionID': SessionID
}

# i tried this 

def profile_token(request):
response = api.execute('FetchToken', request)
return render(request, 'users/profile_token.html')
# and this  

def profile_token(request):
if profile_token:

response = api.execute('FetchToken', request)
return render(request, 'users/profile_token.html')

我想每次我在这里发布问题时,我都会通过自己的找到答案

所以错误是单词"request",我应该使用"r"或除"request(请求("之外的任何其他词,因为它已经被django视图函数保留了

祝好运

def profile(request):
RuName= 'driss_aitkassi-drissait-crm-SB-ijuzzy'
r= {
'RuName': RuName
}
response = api.execute('GetSessionID', r)

print(response)
res =response.text
tree= ET.fromstring(res)
for node in tree.iter('{urn:ebay:apis:eBLBaseComponents}GetSessionIDResponse'):
SessionID= node.find('{urn:ebay:apis:eBLBaseComponents}SessionID').text
print(SessionID)
url_vars = {'SignIn&RuName': RuName, 'SessID': SessionID}
url = 'https://signin.sandbox.ebay.com/ws/eBayISAPI.dll?'
constructed_url=(url + urllib.parse.urlencode(url_vars))  
final_url=urllib.parse.unquote(constructed_url) 

print(final_url) 
context={
'final_url':final_url
}
return render(request,'users/profile.html',context)

最新更新