【问题标题】:How to call a Python script inside a HTML file? [closed]如何在 HTML 文件中调用 Python 脚本? [关闭]
【发布时间】:2017-02-22 19:34:00
【问题描述】:

我正在使用 HTML5、Django、Python 3.4

1) 我想要 2 使用 Javascript/Jquery/AJAX/DJANGO/Anyshitstuff 在 html5 文档中调用 python 脚本

代码(pyscript.py)=

print("Hello everyone")

注意文件pyscript.pymywebpage.html r 在同一个名为templates 的目录中

2)我想要 2 在另一个 python 脚本中调用一个 python 脚本,我该怎么做?

1.py

a=5

2.py

//here i include python script that is 1.py then
print(a)

【问题讨论】:

  • 您不能从 HTML 文档调用 python 脚本。但是您可以使用 javascript 向您的 django 服务器发出请求:了解 AJAX。对于第 2 点,请了解 python modules
  • 我认为在提出这些问题之前,您需要解决一些基本的误解:如果您使用 Django,为什么要“调用” Python 脚本?使用 AJAX 可以做到这一点,但我怀疑您对前端和后端之间的关系不太清楚。

标签: python django html django-models


【解决方案1】:

你不能这样做(在 HTML5 中调用 python 脚本) 但是你可以使用 Javascript、AJAX 来做到这一点

How do you execute a server-side Python script using jQuery?

【讨论】:

    猜你喜欢
    • 2018-02-17
    • 2019-12-18
    • 2014-04-04
    • 1970-01-01
    • 1970-01-01
    • 2011-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多