Javascript ValueError:视图未返回HttpResponse对象。它没有返回任何结果。(Django/ImgKit)
ValueError:视图未返回HttpResponse对象。它反而返回None.Django/ImgKit 我正在尝试使用fetchapi将用户在前端选择的内容连接到后端,然后返回一个json响应。对于他们选择的任何html文件,我想将其转换为一个图像,以供他们预览 不确定我为什么会面临此错误:Javascript ValueError:视图未返回HttpResponse对象。它没有返回任何结果。(Django/ImgKit),javascript,python,django,django-views,imgkit,Javascript,Python,Django,Django Views,Imgkit,ValueError:视图未返回HttpResponse对象。它反而返回None.Django/ImgKit 我正在尝试使用fetchapi将用户在前端选择的内容连接到后端,然后返回一个json响应。对于他们选择的任何html文件,我想将其转换为一个图像,以供他们预览 不确定我为什么会面临此错误: def folder_view(request): if request.method == 'POST': if json.loads(request.body)['temp
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')
错误似乎来自此行:html\u img=imgkit.from\u urltemplate.html.url,False,config=config
删除此行后,将不再显示错误您没有返回任何内容:
def folder_view(request):
if request.method == 'POST':
.........
....
return render(request,your_template.html,context) #add here
当其中一个ifs或try子句失败时,您不会返回HttpResponse对象。