Связь и обмен данными между двумя функциями с помощью django
Кто может подсказать мне, как использовать результаты одной функции в качестве входных параметров для другой функции?
Вот мой код :
def even_point(request):
longitude=request.POST['longitude']
latitude=request.POST['latitude']
ref_location = Point(float(longitude), float(latitude))
all_evens = Even.objects.all()
return render(request, 'even_map_point.html', {'all_evens': all_evens,
'longitude':longitude, 'latitude':latitude, 'ref_location':ref_location})
def EvenDataPoint(request, ref_location):
name = serialize('geojson', Evenobjects.filter(geom__contains=ref_location))
return HttpResponse(name,content_type='json')
У меня следующая ошибка:
TypeError: EvenementDataPoint() отсутствует 1 необходимый позиционный аргумент: 'ref_location'
Как заставить вторую функцию распознать значение местоположения, вычисленное в первой функции?
Я думаю, что самый простой способ достичь этого - использовать сессию django примерно так
def even_point(request):
longitude=request.POST['longitude']
latitude=request.POST['latitude']
ref_location = Point(float(longitude), float(latitude))
request.session['ref_location'] = ref_location #nouveau
all_evens = Even.objects.all()
return render(request, 'even_map_point.html', {'all_evens': all_evens,
'longitude':longitude, 'latitude':latitude, 'ref_location':ref_location})
def EvenDataPoint(request):
ref_location = request.session.get('ref_location',None) #nouveau
name = serialize('geojson', Even.objects.filter(geom__contains=ref_location))
return HttpResponse(name,content_type='json')
Обязательно удалите сессию после завершения фильтрации