尝试在 Jupyter Notebook 中创建 iframe 时出现错误:

我收到错误:


Refused to frame 'http://localhost:8888/' because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self'".

当尝试从包含另一个本地 HTML 文件的 iframe 的本地 HTML 文件创建 iframe 时。


例如test-outer.html:


<!DOCTYPE html>

<html>

<body>

<iframe sandbox="allow-scripts" id="0" src="./test-inner.html" width="100" height="100"  frameborder="0"></iframe>

</body>

</html>

使用 Jupyter Notebook Python 代码:


from IPython.display import IFrame

IFrame(src='test-outer.html', width=200, height=200)

test-inner.html可以包含任何东西。


test-outer.html在单独的浏览器选项卡上完美加载。问题在于将其加载到 Jupyter Notebook 中。


梦里花落0921
浏览 180回答 1
1回答

潇潇雨雨

虽然这是一个老问题,但是对新求知者有所帮助。您需要在 jupyter_notebook_config.py 中添加标头c.NotebookApp.tornado_settings={'headers':&nbsp;{'Content-Security-Policy':&nbsp;"frame-ancestors&nbsp;self&nbsp;https://my-website-url.com/jupyter&nbsp;"}}https://my-website-url.com/jupyter是您在其中加载 jupyter 笔记本的 url&nbsp;iFrame。这适用于 Firefox 和 Chrome。未在 Safari 中测试。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python