ValueError: The view didn't return an HttpResponse object. It returned None instead.
(Django/ImgKit)
I am trying to use a fetch api to connect what the user selects in the frontend to the backend and then return a json response. For whichever html file they select, i want to convert it into an image to be displayed for them to preview
Not sure why i am facing this error:
def folder_view(request):
if request.method == 'POST':
if json.loads(request.body)['template'] == 'template':
try:
folder = json.loads(request.body)['folder']
templates = Template.objects.filter(user=request.user, folder=folder).values('template_name')
user_templates=[]
for template in templates:
config = imgkit.config(wkhtmltoimage=WKHTMLTOPDF_PATH, xvfb='/usr/bin/xvfb-run')
html_img = imgkit.from_url(template.html.url, False, config=config)
user_templates.append(html_img)
return JsonResponse({'user_templates': user_templates })
except Exception as e:
print('test')
Error seems to be coming from this line: html_img = imgkit.from_url(template.html.url, False, config=config)
Once this line is removed, error wont be seen anymore
you didn't return anything :