I am looking for a HTML converter which allows me to convert .doc to HTML in my Django project.
In my project, .docx files can be converted but not .doc files.
.docx file processing was done as follows.
view.py:
@csrf_exempt
@api_view(['POST'])
def fileload(request):
if request.method == 'POST' and request.FILES['file']:
urls = settings.MEDIA_ROOT+'fileload/'
fs = FileSystemStorage(location=urls, base_url=urls)
filename = fs.save(file.name, file)
filepath = urls + file.name
ext = os.path.splitext(filepath)[1]
print(ext)
html=None
code = '0'
if ext == '.docx':
html = get_docx_html(filepath)
code = '1'
fs.delete(file.name)
data = {
'code': code,
'html': html
}
response = JsonResponse(data)
return response
def get_docx_html(path):
with open(path, "rb") as docx_file:
result = mammoth.convert_to_html(docx_file)
html = result.value
messages = result.messages
return html
In the same way, doc files are not converted.
I'd like to have the .doc file converted.
Any idea of approach that can be recommended or sample code? Thanks a lot.