def analysis_view(request): if request.method == "POST": body_unicode = request.body.decode('utf-8') body = json.loads(request.body) print(request.body) content = body['b64_image'] filename = str(dateformat.format(timezone.now(), 'Y-m-d_H-i-s')) + '.jpg' post = Post() post.image = ContentFile(base64.b64decode(content), name=filename) post.name = filename post.save() object, result_data, total_percent = analysis.draw_line(post.pk) user_image = base64.b64encode(post.image.read()) result_image = base64.b64encode(object.result.read()) print(test) data = { "message" : str(result_data[0]), "image_name" : post.image.name.split('.')[0], "image" : str(user_image), "result" : str(result_image) } return JsonResponse(data) else: return HttpResponse("get is worng request")
def test(request): if request.method == "POST": post = Post() post.name = request.FILES["image"].name post.image = request.FILES["image"] post.save() object, result_data = analysis.draw_line(post.pk) data = { "message": result_data, "image": post.image.url, "result": object.result.url } return render(request, "test.html", data) else: return render(request, "test.html")