iframe 标签内嵌 jupyter notebook

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/zxm1306192988/article/details/88601249

默认 jupyter notebook 的 HTTP Content-Security-Policy (CSP) 安全策略是不允许父类将 jupyter notebook 页面嵌入到 <frame>、<iframe>、<object>、<embed><applet> 中的。

使用 <frame> 嵌入:

<iframe id='rightframe' name='leftiframe' width="70%" src='https://192.168.1.128:9999/tree?'></iframe>

会报错:

Refused to display ‘https://192.168.1.128:9999/tree?’ in a frame because an ancestor violates the following Content Security Policy directive: “frame-ancestors ‘self’”.

需要修改 jupyter notebook 配置使其允许指定IP的父类元素 内嵌 jupyter notebook 页面。

(1)修改 vim ~/.jupyter/jupyter_notebook_config.py

c.NotebookApp.tornado_settings = { 'headers': { 'Content-Security-Policy': "frame-ancestors http://*.*.*.*:8080 http://192.168.1.101:8080 http://192.168.1.1:8080 http://10.5.114.78:8080 http://localhost:8080 'self' " }}

其中 ‘self’ 表示允许本身访问,前面的表示允许前面来自各种IP的嵌入请求。

(2)增加文件 ~/.jupyter/custom/custom.js

define(['base/js/namespace'], function(Jupyter){
	    Jupyter._target = '_self';
});

这样可以使新创建的 notebook在本页打开。

效果:

在这里插入图片描述

参考:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors
https://github.com/jupyter/notebook/issues/886
https://github.com/jupyter/notebook/issues/284#event-491018840

展开阅读全文

Jupyter Notebook的主题编码问题

02-10

最近因为jupyter notebook的白色原装界面太难看了,特别是字体。然后,就install nJupyter themes; 一切都OK,themes也下载下来了,进行 jt -l 也是没问题的,正常n显示出了已经有的各个主题了。n最后,进行 jt -t 主题名 启用时,报错了。无法切换主题:nn(C:\Users\Administrator\Anaconda3) C:\Users\Administrator>jt -lnAvailable Themes:n chesterishn grade3n gruvboxdn gruvboxln monokain oceans16n onedorkn solarizeddn solarizedlnn(C:\Users\Administrator\Anaconda3) C:\Users\Administrator>jt -t grade3nTraceback (most recent call last):n File "c:\users\administrator\anaconda3\lib\runpy.py", line 193, in _run_module_as_mainn "__main__", mod_spec)n File "c:\users\administrator\anaconda3\lib\runpy.py", line 85, in _run_coden exec(code, run_globals)n File "C:\Users\Administrator\Anaconda3\Scripts\jt.exe\__main__.py", line 9, in n File "c:\users\administrator\anaconda3\lib\site-packages\jupyterthemes\__init__.py", line 307, in mainn dfonts=args.defaultfonts)n File "c:\users\administrator\anaconda3\lib\site-packages\jupyterthemes\__init__.py", line 103, in install_themen style_css = stylefx.less_to_css(style_less)n File "c:\users\administrator\anaconda3\lib\site-packages\jupyterthemes\stylefx.py", line 63, in less_to_cssn style_css = lesscpy.compile(tempfile)n File "c:\users\administrator\anaconda3\lib\site-packages\lesscpy\__init__.py", line 18, in compilen p.parse(file=file)n File "c:\users\administrator\anaconda3\lib\site-packages\lesscpy\lessc\parser.py", line 154, in parsen file, lexer=self.lex, debug=debuglevel)n File "c:\users\administrator\anaconda3\lib\site-packages\ply\yacc.py", line 331, in parsen return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)n File "c:\users\administrator\anaconda3\lib\site-packages\ply\yacc.py", line 1024, in parseopt_notrackn lexer.input(input)n File "c:\users\administrator\anaconda3\lib\site-packages\lesscpy\lessc\lexer.py", line 475, in inputn self.lexer.input(f.read())nUnicodeDecodeError: 'gbk' codec can't decode byte 0x8b in position 44256: illegal multibyte sequencen 问答

没有更多推荐了,返回首页