Flask网页中的Jupyter Lab IFrame

时间:2019-02-05 13:45:10

标签: python iframe flask jupyter jupyter-lab

我想在烧瓶(http://localhost:8888)中看到正在运行的Jupyter(http://127.0.0.1:5000)。

我基本上会跟踪这些链接。 Render a Jupyter Notebook Iframe in Flask

但是这些错误消息在Chrome控制台日志中。没有任何显示,只有白屏。

Refused to display 'http://localhost:8888/lab?' in a frame because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'http://127.0.0.1:5000/' 'self'".

如何通过Flask应用程序控制Jupyter Lab?


我的代码

main.py

@app.route("/")
def jupyter():
    src = "http://localhost:8888/lab?"
    return render_template("iframe.html", iframe=src)

iframe.html

<iframe frameborder='0' noresize='noresize' sandbox="allow-same-origin allow-popups allow-scripts" style='position: absolute; background: transparent; width: 100%; height:100%;' src="{{ iframe }}" frameborder="0"></iframe>

jupyter_notebook_config.py

c.NotebookApp.allow_origin = '*' #Basic permission
c.NotebookApp.disable_check_xsrf = True #Otherwise Jupyter restricts you modifying the Iframed Notebook
c.NotebookApp.token = '' #In my case I didn't want to deal with security
c.NotebookApp.trust_xheaders = True #May or may not make a difference to you

c.NotebookApp.tornado_settings = {
    'headers': {
        'Content-Security-Policy': "frame-ancestors 'self' http://127.0.0.1:5000/ http://127.0.0.1:5000/*",
    }
} 

1 个答案:

答案 0 :(得分:0)