0

I have a python file on my server. I want to run this file whenever user clicks submit button. Both my files .py and .html are in different directories. And I also cant use any framework

How to do this?

James Z
  • 12,209
  • 10
  • 24
  • 44
  • 2
    use Python framework like Django, Flask, Bottle to create web page. And you need server which can run Python code - Django,Flask, Bottle - or it uses CGI to run scripts in different languages - or it can run PHP which could run Python code. Using only HTML and JavaScript you can't run Python code – furas Feb 24 '20 at 11:54
  • Agree on @vishakha-mishra comment. You'll need some server side technology to do that. As you want to run a python script, I'd suggest using some python web framework. – cristianoms Feb 24 '20 at 12:25
  • flask is the simplest https://flask.palletsprojects.com/en/1.1.x/quickstart/ – hounded Mar 03 '20 at 03:18

1 Answers1

1

One option (as suggested by furas) is to use a python framework (Django, Flask, Bottle) on the backend to create an API server. You could equally do this in node with a call to require('child_process').exec()

The other older method is to configure FastCGI on your webserver, which can automatically turn your python file into a url. Here are some stackoverflow answers for that method:

James McGuigan
  • 7,542
  • 4
  • 26
  • 29