Skip to content

Instantly share code, notes, and snippets.

@godfather68
Created January 18, 2021 20:00
Show Gist options
  • Save godfather68/2d8e3e884dee4b20a4e57a6728166773 to your computer and use it in GitHub Desktop.
Save godfather68/2d8e3e884dee4b20a4e57a6728166773 to your computer and use it in GitHub Desktop.
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