Reputation: 428
I am using django rest framework and I want after a POST request in a URL to follow a GET request to another URL with processing some data coming from the POST request.
I attach my views.py:
from rest_framework.response import Response
from rest_framework.decorators import api_view
from importer import event_import_data
from utils import optimization_solution
@api_view(['POST'])
def event(request):
event_data_post = request.data
return Response(event_data_post)
@api_view(['GET'])
def optimization(request):
response_dict = {}
event_data = event_import_data(event_data_post)
response_dict = optimization_solution(event_data)
return Response(response_dict)
So, initially I POST a json file in a URL and then I expect by using the dictionary provided by the POST request to use it in the GET request in another URL.
However, I am getting the following error:
NameError: name 'event_data_post' is not defined
Any idea of what is causing the error and how can I bypass it?
Upvotes: 0
Views: 1391
Reputation: 31
You're not saving the 'event_data_post' in your event method your just saving it temporarily if you want to save it you should have a model and a serializer and give your data to the serializer to save it in your model.
serializer = SnippetSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
Upvotes: 1