【问题标题】:Python terminal in html?html中的Python终端?
【发布时间】:2018-10-16 09:24:18
【问题描述】:

由于标题,您可以在阅读之前对此投反对票(编辑:感谢您的理解),但其他问题只是回答如何在 html 中运行 python 程序,但我想做的是在 html 中使用 python 终端。

所以伙计们,我的脑海里实际上有一个很大的问题。我怎样才能像终端一样在 html 中使用 python 程序。

这是我的项目,它将是一本交互式词典,您可以学习词汇。

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
    font-family: Arial
}

* {
    box-sizing: border-box;
}

/* The browser window */
.container {
    border: 3px solid #f1f1f1;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
}

/* Container for columns and the top "toolbar" */
.row {
    padding: 10px;
    background: #f1f1f1;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
}

.scriptcontainer {
    padding: 10px;
    background: #ffffff;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
}

.row2 {
    padding: 5px;
    background: #cc0000;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
}

/* Create three unequal columns that floats next to each other */
.column {
    float: left;
}

.left {
    width: 15%;
}

.right {
    width: 10%;
}

.middle {
    width: 75%;
}

/* Clear floats after the columns */
.row:after {
    content: "";
    display: table;
    clear: both;
}

/* Three dots */
.dot {
    margin-top: 4px;
    height: 12px;
    width: 12px;
    background-color: #bbb;
    border-radius: 50%;
    display: inline-block;
}

/* Style the input field */
input[type=text] {
    width: 100%;
    border-radius: 3px;
    border: none;
    background-color: white;
    margin-top: -8px;
    height: 25px;
    color: #666;
    padding: 5px;
}



.bar {
    width: 17px;
    height: 3px;
    background-color: #aaa;
    margin: 3px 0;
    display: block;
}

/* Page content */
.content {
    padding: 10px;
}
</style>
</head>
<body>

<div class="container">
  <div class="row">

    <div class="column middle">
        <h4><font size="6" type="Times">VocaDict</font></h4>
   </div>

  </div>

  <div class="content">
    <h3>=>Your dictionary:</h3>
      <div class="row2"><div class="content"><div class="scriptcontainer">        <script>//This is where your dictionary will go!</script></div></div></div>
      </div>

      <div class="content">
    <h3>=>Study lists:</h3>
      <div class="row2"><div class="content"><div class="scriptcontainer">    <script>//This is where your dictionary will go!</script></div></div></div>
      </div><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br>    <br><br><br><br><br><br><br><br><br><br>

  </div>


</body>
</html> 

我要问的是关于这些地方:

<div class="content"><div class="scriptcontainer">    <script>//This is the place I want python terminal to be!</script>

我希望这些地方像一个 python 终端。当页面加载时它会运行程序,它不会影响任何其他东西,就像一个独立的东西,但它会留在页面上并且是交互式的。

这可能吗?如果可以,怎么做?

谢谢!

【问题讨论】:

  • 网络上有一些地方提供 Python(和其他)REPL。你可以检查那些。我敢打赌,其中一些甚至有 github 页面。否则,这对 SO 来说太宽泛了。
  • 漂亮的头像 Elvez。不幸的是,尽管是饥荒的粉丝。我同意这个问题不属于 SO,就像@jdv 所说的那样。祝你好运,保重朋友!
  • 重读此问题后,我突然想到这可能是XY Problem,因为您要求解决假设的问题,但我们真的不知道为什么。见How to Ask。你想做什么,你尝试了什么,你得到了什么结果?
  • @RannLifshitz 谢谢,但我不明白为什么人们总是告诉我我的问题不适合 SO。我只是卡住了,我在网上搜索的东西通常不会给我正确的答案。所以我唯一的选择就是问。
  • Elvez - 正如@jdv 所说,有一个关于如何在 SO 上提问的专用线程:stackoverflow.com/questions/how-to-ask 不遵守此标准可能会导致其他 SO 用户的否决。这不是个人的,而是一种帮助来自多个国家的个人相互交流的协议的执行。祝你好运朋友。

标签: python html python-2.7


【解决方案1】:

你到底想在这里做什么?如果你真的想用 HTML 运行 python 脚本,那么选择 CGI。由于您不能直接运行python,您可能必须使用以下内容,

http://karrigell.sourceforge.net/en/pythoninsidehtml.html

http://www.skulpt.org/

但最好的方法是使用 python-cgi 编程https://www.tutorialspoint.com/python/python_cgi_programming.htm

【讨论】:

  • 我真的希望有人能用一句话来回答:“CGI”。
  • 谢谢!我想这就是我想要的。
【解决方案2】:

这是不可能的。

我自己之前也有过这个问题。显然目的是为其他脚本腾出空间,至少我是这样认为的:

<script type="text/javascript">
<script type="text/python">

它需要一个实现这一点的浏览器。也许这个引擎:https://www.gnu.org/software/pythonwebkit/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-05
    • 2015-06-08
    • 2015-06-26
    • 1970-01-01
    • 2021-12-25
    • 2012-11-21
    • 2013-12-16
    • 2015-09-10
    相关资源
    最近更新 更多