【问题标题】:Jupyter lab IFrame in Flask web pageFlask 网页中的 Jupyter 实验室 IFrame
【发布时间】:2019-06-29 08:33:17
【问题描述】:

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

我基本上是跟进这些链接。 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/*",
    }
} 

【问题讨论】:

    标签: python iframe flask jupyter jupyter-lab


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-15
    • 2018-08-23
    相关资源
    最近更新 更多