I'm trying to run a python script using the webpage I created in pug, express in node. I'm more familar with python than node. Using the below how can I run the python script? I have python shell included but not sure how to run the python script when I click the button on the pug webpage.
server.js
// require all dependencies
var express = require('express');
var app = express();
var PythonShell = require('python-shell');
// set up the template engine
app.set('views', './views');
app.set('view engine', 'pug');
var options = {
mode: 'text',
pythonOptions: ['-u'],
scriptPath: '../hello.py',
args: ['value1', 'value2', 'value3']
};
// GET response for '/'
app.get('/', function (req, res) {
// render the 'index' template, and pass in a few variables
res.render('index', { title: 'Hey', message: 'Hello' });
PythonShell.run('hello.py', options, function (err, results) {
if (err) throw err;
// results is an array consisting of messages collected during execution
console.log('results: %j', results);
});
});
// start up the server
app.listen(3000, function () {
console.log('Listening on http://localhost:3000');
});
index.pug
html
head
title= title
body
h1= message
a(href="http://www.google.com"): button(type="button") Run python script