I have a view :
def add_view(request):
if request.method == "POST":
files = request.FILES.getlist("file")
response_data = {}
for file in files:
my_model = MyModel()
my_model.my_file = file
my_model.save()
id_info = my_model.id
response_data.append(id_info)
return HttpResponse(json.dumps(response_data), content_type="application/json")
Here lets say if there are 5 files then I want to send the id of 5 file in response through json. Here its saying local variable response_data referenced before assignment.
I want to send the id of all 5 files. How to do this ?