GVKun编程网logo

通过 javascript 调用来使用 python 脚本(javascript调用python程序)

2

在本文中,我们将为您详细介绍通过javascript调用来使用python脚本的相关知识,并且为您解答关于javascript调用python程序的疑问,此外,我们还会提供一些关于(Django-Ja

在本文中,我们将为您详细介绍通过 javascript 调用来使用 python 脚本的相关知识,并且为您解答关于javascript调用python程序的疑问,此外,我们还会提供一些关于(Django - Javascript) html 模板中的计时器 javascript 和 datetime python 变量、/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python:无法打开文件“esptool.py”、CMake 不断从 cygwin python 中获取 Python,如何从 Windows 安装的 Python 中获取、Error: Can‘t find Python executable “python“, you can set the PYTHON env variable的有用信息。

本文目录一览:

通过 javascript 调用来使用 python 脚本(javascript调用python程序)

通过 javascript 调用来使用 python 脚本(javascript调用python程序)

如何解决通过 javascript 调用来使用 python 脚本

所以我得到了这个 python 脚本,它删除重复的文件并将它们分类到与其扩展名对应的文件夹中。 我想要做的是,当有人将文件夹上传到网站而不是点击一个按钮时,python 脚本被调用并启动,它会创建一个文件夹来存储排序的文件,供用户以后下载这些文件。

解决方法

由于 javascript 是客户端,因此您需要设置某种后端来处理用户发送的数据,然后对其进行排序。 moustafa 链接了一个很好的解释,我推荐阅读它,你应该被排序。

(Django - Javascript) html 模板中的计时器 javascript 和 datetime python 变量

(Django - Javascript) html 模板中的计时器 javascript 和 datetime python 变量

如何解决(Django - Javascript) html 模板中的计时器 javascript 和 datetime python 变量

我在 javascript 网上找到了一个计时器倒计时,它工作正常......

我必须将 python 变量传递给它,但是,虽然结果是正确的,倒计时没有运行,它显示了正确的剩余时间,但没有继续减少(至少我刷新了页面)...

这是我的一段代码:

  • views.py
import datetime

auction = Auction.objects.get(id=id)
endDateFormat = auction.endDate.strftime("%Y-%m-%dT%H:%M:%s")
startDateFormat = datetime.datetime.Now().strftime("%Y-%m-%dT%H:%M:%s")
  • template.html

             <script>
                  // Set the date we''re counting down to
                  var countDownDate = new Date("{{endDateFormat}}").getTime();
    
                  // Update the count down every 1 second
                  var x = setInterval(function() {
    
                      // Get today''s date and time
                      var Now = new Date("{{startDateFormat}}").getTime();
    
                      // Find the distance between Now and the count down date
                      var distance = countDownDate - Now;
    
                      // Time calculations for days,hours,minutes and seconds
                      var days = Math.floor(distance / (1000 * 60 * 60 * 24));
                      var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
                      var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
                      var seconds = Math.floor((distance % (1000 * 60)) / 1000);
    
                      // Output the result in an element with id="demo"
                      document.getElementById("demo").innerHTML = days + "d " + hours + "h " + minutes + "m " + seconds + "s ";
    
                      // If the count down is over,write some text
                      if (distance < 0) {
                          clearInterval(x);
                          document.getElementById("demo").innerHTML = "EXPIRED";
                      }
                  },1000);
              </script>
    

谢谢大家!

解决方法

试试这个!给定一个 view

def timer_page_view(request):
    auction = Auction.objects.last()
    context = {
        ''start_date'': auction.start_date.strftime("%Y-%m-%dT%H:%M:%S"),''end_date'': auction.end_date.strftime("%Y-%m-%dT%H:%M:%S"),}
    return render(request,''timer_page.html'',context=context)

您的 timer_page.html 模板可能如下所示:

<body>
    <p>start date is {{ start_date }}</p>
    <p>start date is {{ end_date }}</p>
    <div id=''demo''>time difference</div>
</body>

<script>

// Set the date we are counting to
var countDownDate = new Date(''{{ end_date }}'');

// Set the date we are counting from
var countFromDate = new Date("{{ start_date }}");

// Set inital distance in seconds
var distance = (countDownDate.getTime() - countFromDate.getTime()) / 1000;

// Set initial time difference in the DOM
var days = Math.floor((distance / (60 * 60 * 24)));
var hours = Math.floor((distance - (days * (60 * 60 * 24))) / (60 * 60));
var minutes = Math.floor((distance - ((days * (60 * 60 * 24)) + (hours * (60 * 60)))) / 60);
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
document.getElementById("demo").innerHTML = days + '' ''  + hours + '' '' + minutes + '' '' + seconds;

// Timer
let active = true;

startTimer = () => {
    if (active) {
        var timer = document.getElementById("demo").innerHTML;
        let nums = timer.split(" ").map(num => parseInt(num))
        let day = nums[0];
        let hour = nums[1];
        let min = nums[2];
        let sec = nums[3];
        if (sec == 0) {
            if (min == 0) {
                hour--;
                min = 59;
                if (hour == 0){
                    day--;
                    hour = 23;
                }
                if (hour < 10) hour = "0" + hour;
            } else {
                min--;               
            }
                if (min < 10) min = "0" + min;
            sec = 59;
        } else {
            sec--;
            console.log(sec)
            if (sec < 10) sec = "0" + sec;
        }
        document.getElementById("demo").innerHTML = day + '' ''  + hour + '' '' + min + '' '' + sec;
        setTimeout(startTimer,1000);
    }
}
startTimer();

</script>

计时器会在此处立即开始,但您可以根据自己的喜好进行调整。

/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python:无法打开文件“esptool.py”

/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python:无法打开文件“esptool.py”

如何解决/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python:无法打开文件“esptool.py”

我正在 mac OS X 上使用 ESP8266Flash.app 更新 ESP8266 固件。 但是当我开始刷固件时出现以下错误:

/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can''t open file ''esptool.py'': [Errno 1] Operation not permitted."

我该如何解决这个问题?

CMake 不断从 cygwin python 中获取 Python,如何从 Windows 安装的 Python 中获取

CMake 不断从 cygwin python 中获取 Python,如何从 Windows 安装的 Python 中获取

如何解决CMake 不断从 cygwin python 中获取 Python,如何从 Windows 安装的 Python 中获取

我有一个看起来像这样的 CMake 脚本:

  1. find_program(PYTHON_COMMAND NAMES python3 python)

问题是它检测到安装在 Cygwin 安装中的 python。 输出总是:

  1. -- PYTHON_PATH:C:/cygwin64/bin/python3

我希望它取自:

  1. c:\\python36-64\\python

在windows PATH变量中,Cygwin bin在路径的最后一个,windows安装在第一个 但它只检测到 Cygwin python,
怎么改?

Error: Can‘t find Python executable “python“, you can set the PYTHON env variable

Error: Can‘t find Python executable “python“, you can set the PYTHON env variable

在启动vue项目的时候,安装node.js组件node-sass过程中报错了,错误提示如下
Error: Can’t find Python executable “python”, you can set the PYTHON env variable

由错误提示可知:Node.js 在安装模块组件node-sass的时候,node.js缺少Visual Studio2015 Build Tools相关的组件和python的环境,如果安装了vs2015组件的小伙伴们就不用安装Visual Studio2015 Build Tools相应的组件,只用安装python2.7即可解决缺少的python组件的问题。

欲安装python2.7,请至python官网:www.python.org 下载,然后配置好python的环境变量即可。

不过博主我并不推荐上述的解决方案,因为对于程序员来说,效率第一,上述的问题一个命令就可以轻松解决你所遇到的麻烦,前面说了那么多,无非就是想告诉在看本篇博客的同仁们放下浮躁的心,遇到问题首先不是急着去解决问题,而是分析为什么会这样,然后才能水到聚成的去找到解决问题的方法。

运行下面这个命令即可解决你们遇到的Error问题

npm install --global --production windows-build-tools

:上面讲述了一堆就是为了讲述此命令是干嘛的,上面已经描述很详细了,就不再赘述了,该操作与上述的一堆操作无异,效果却是一样的。

然后运气不好的小伙伴可能接着会遇到一个坑,那就是执行了:npm install --global --production windows-build-tools这个命令的人细心点会发现执行到一半就卡住了,这个卡住了没有红字重点提示,而且下方还有英文在等待中,粗心的小伙伴可能以为是命令执行完了,组件安装好了,其实不然,我这边已经解决了,就无法复现了,具体点就是中文的提示,提示我们由于有类似组件在运行或者下载导致无法继续下载安装组件了。稳妥点的解决办法是,将电脑重启,将底层正在运行的模块干掉,待电脑重启后再执行npm install --global --production windows-build-tools这条命令即可,博主我就是这样解决的,稳稳的幸福就会浮现在你面前如下图所示,你的可能和我不一样,因为我已经跑成功过一次了,没有你的那么多细节的log打印。
在这里插入图片描述

然后就是在你的项目下shift+鼠标右击你的项目运行npm run dev即可启动vue项目了。

今天关于通过 javascript 调用来使用 python 脚本javascript调用python程序的分享就到这里,希望大家有所收获,若想了解更多关于(Django - Javascript) html 模板中的计时器 javascript 和 datetime python 变量、/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python:无法打开文件“esptool.py”、CMake 不断从 cygwin python 中获取 Python,如何从 Windows 安装的 Python 中获取、Error: Can‘t find Python executable “python“, you can set the PYTHON env variable等相关知识,可以在本站进行查询。

本文标签: