I would like to use a variable outside of the function in which it was defined. I have only ever passed data to different templates and have not had to reference that data afterwards so I am unsure as to how I should proceed.
views.py
def new_opportunity_company_id(request):
company = request.GET.get('selected_company')
company_obj = cwObj.get_company(company)
company_id = company_obj[0]['id']
return company_id
def new_opportunity_location(request):
for company_id in new_opportunity_company_id(request):
locations = cwObj.get_sites(company_id)
context = {'locations': locations}
return render(request, 'website/new_opportunity_location.html', context)
Any help would be greatly appreciated, I am still new to Django/Python. Thanks!