A
A
Andrey2018-03-07 16:52:26
Python
Andrey, 2018-03-07 16:52:26

How to run python script from html?

There is a simple html page with a popup.
You need to run a python script when opening a popup (the popup opens when you click on the button).
There is a loop in the script and it is executed until it receives data from outside, and when the loop ends, information is displayed, this information must be displayed in the popup.
How can this be implemented?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2018-03-07
@webinar

Let's say you have a modal from bootstrap3, it has an event that fires when it opens, then like this:

$('#myModal').on('shown.bs.modal', function () {
  $.get('/url/to/my/script/',function(data){
     alert('ответ пришел');
  });
})

B
blayloock012018, 2018-03-07
@blayloock012018

1. run python script from html on OpenServer
-----------------index.py
#!D:\Python27\python.exe
# -*- coding: UTF-8 -* -
# //coding: utf-8
# coding=utf-8
# vim: set fileencoding=utf-8 :
print "Content-Type: text/html\r\n"
print "hello world"
print "instead of #! python2 you can d:/Python27/python.exe"
-------------.htaccess
DirectoryIndex index.py
Options +FollowSymLinks +ExecCGI
-------------.httpd. conf: (find line AddHandler )
AddHandler cgi-script .cgi .pl .py
2. run python script from html on python hosting , for example timeweb
-----------------index. py
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# //coding: utf-8
# coding=utf-8
# vim: set fileencoding=utf-8 :
print "Content-Type: text/html\r\n"
print "hello world"
-------------.htaccess
DirectoryIndex index.py
Options +FollowSymLinks +ExecCGI
permissions rwx------ (700) for py , otherwise error500

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question