def ajax_create_member(request): member_form = MemberForm() pk = request.GET.get('pk') global e e.append(pk) if request.method == 'POST': name = request.POST['name'] surnames = request.POST['surnames'] category = request.POST['category'] email = request.POST['email'] CI = request.POST['CI'] academic_year = request.POST['academic_year'] form = MemberForm(request.POST, request.FILES) if form.is_valid(): print('Este es el pk') print(e[0]) project = Project.objects.get(pk=d[0]) d = [] member = Member.objects.create( name=name, surnames=surnames, category=category, email=email, CI=CI, academic_year=academic_year ) project.member=member project.save() projects = Project.objects.all() data = { 'msg': 'El integrante se ha guardado satisfactoriamente', 'page': render_to_string('project/list_project.html', {'projects': projects}, request=request), 'header': render_to_string('project/dinamic_project.html', request=request), } return JsonResponse(data) else: data = { 'page': render_to_string('project/member/add.html', {'form': member_form}, request=request) } return JsonResponse(data) Error : > response = wrapped_callback(request, *callback_args, > **callback_kwargs) File "C:\Users\Edivaldo Gomes\PycharmProjects\science\applications\projects\views.py", line > 423, in ajax_create_other_member return JsonResponse(data) > UnboundLocalError: local variable 'data' referenced before assignment > [2019/01/25 14:00:15] HTTP POST /ciencia/project/member/other/add 500 > [0.19, 127.0.0.1:56663]