Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular和Django:SecurityError:未能执行';toDataURL';在';HTMLCanvasElement';:受污染的画布不得出口_Django_Angular_Html2canvas - Fatal编程技术网

Angular和Django:SecurityError:未能执行';toDataURL';在';HTMLCanvasElement';:受污染的画布不得出口

Angular和Django:SecurityError:未能执行';toDataURL';在';HTMLCanvasElement';:受污染的画布不得出口,django,angular,html2canvas,Django,Angular,Html2canvas,我与Angular和Django合作。在angular中,我使用jspdf和html2canvas生成报告,为此,我加载了存储在Django中的图像,在想要生成pdf的时候,我生成了标题中提到的错误。在Django中,我添加了corsheaders,并授予从Angular访问的权限: DEBUG = True ALLOWED_HOSTS = ['localhost', '127.0.0.1'] CORS_ORIGIN_ALLOW_ALL = False CORS_ORIGIN_WHITELI

我与Angular和Django合作。在angular中,我使用jspdf和html2canvas生成报告,为此,我加载了存储在Django中的图像,在想要生成pdf的时候,我生成了标题中提到的错误。在Django中,我添加了corsheaders,并授予从Angular访问的权限:

DEBUG = True
ALLOWED_HOSTS = ['localhost', '127.0.0.1']

CORS_ORIGIN_ALLOW_ALL = False

CORS_ORIGIN_WHITELIST = [
'http://localhost:4200',
]

CORS_ALLOW_METHODS = list(default_methods) + [
'POKE',
]

CORS_ALLOW_HEADERS = list(default_headers) + [
'my-custom-header',
]
用于生成pdf的角度函数:

pdf () {
html2canvas(document.querySelector("#content"), {allowTaint : 
true}).then(canvas => {

  var img=new Image(); img.crossOrigin="anonymous"
  img = canvas.toDataURL("image/png");
    var doc = new jsPDF();
    doc.addImage(img, 'JPEG', 0, 10);
    doc.save('test.pdf');
  });
  }

查看页面时建议添加crossOrigin=“anonymous”,但这对我不起作用

除非绝对必要,否则请不要将信息作为图像共享。请参阅:。已编辑。。。。。。。。。