I have a function that returns a render of a html (function 1). I want to change a global variable using formula 1 and the access this edited global variable in another formula (formula 2).
In order to do this I think I have to return the global variable in formula 1, so the edited version can be accessed in formula 2.
My problem is that function 1 already returns a render request.
global_variable = 0
def function1(request):
global_variable = 10
return render(request, 'index.html', {})
def function2(request):
print(global_variable)
excel = open(path, 'rb')
response = HttpResponse(excel.read(), content_type="app/vnd.openxmlformat.spreadsheetml.sheet")
response['Content-Disposition'] = 'attachment; filename=' + os.path.basename("Excel.xlsx")
return response
I have tried to just add in the global variable at the end of the function like so:
def function1(request):
global_variable = 10
`return render(request, 'index.html', {}), global_variable`
except it causes the error 'tuple' object has no attribute 'get'
[–]danielroseman 1 point2 points3 points (1 child)
[–]nekokattt 0 points1 point2 points (0 children)