Created
January 18, 2021 20:00
-
-
Save godfather68/2d8e3e884dee4b20a4e57a6728166773 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.views.decorators.csrf import csrf_exempt | |
import json | |
... | |
# Create your views here. | |
class HomeView(FormView): | |
form_class = UploadForm | |
template_name = 'index.html' | |
success_url = '/' | |
# COMMENT OUR FORM VALID METHOD AS WE WON4T NEED IT | |
# def form_valid(self, form): | |
# upload = self.request.FILES['file'] | |
# print(upload) | |
# print(type(pytesseract.image_to_string(Image.open(upload)))) | |
# return super().form_valid(form) | |
@csrf_exempt | |
def process_image(request): | |
if request.method == 'POST': | |
response_data = {} | |
upload = request.FILES['file'] | |
content = pytesseract.image_to_string(Image.open(upload)) | |
response_data['content'] = content | |
return JsonResponse(response_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment