1

I'm new to backend and I've written a python script which imports libraries like Flask, sqlalchemy. From taking help from here and there I've been successfully able to get JSON as response to a get call using localhost or http://127.0.0.1/.

Now that this is done I want to take this action on a live server so right now I've hostgator and I've created a folder there so it'll be like mydomain.com/api/. Now my questions is that do I need to place an index.html in this folder which makes a call to run myscript.py or I can directly call mydomain.com/api/myscript.py and it'll return the JSON?

My script is basically a recommendation model that returns recommendations to users upon request.

Chaudhry Talha
  • 7,231
  • 11
  • 67
  • 116

2 Answers2

0

It's possible to make a request via PHP with the curl_* functions, or you can do the same in JavaScript (e.g. within your HTML file) using AJAX (XMLHttpRequest).

Connor Gurney
  • 597
  • 2
  • 6
  • 16
0

If you are using Flask in your Python script, it is meant to work where the Python program runs all the time, and people's browsers connect to it. It is not mean to work where you put it in a folder and Hostgator's web server invokes it when requests come in; for that you would use the CGI module instead.

If you are buying a server from HostGator, you can log in to the server over SSH and run your script from the command line. Then you would navigate to your server's IP address or domain name in a browser to see if it works, and then you would work out a way to get your app to run all the time, and not just while you are connected and running it manually.

If you are buying just web hosting from HostGator, on the other hand, you may have bought the wrong service. You need access to a computer that can run your Flask app all the time, not just a folder that is served to the web for you.

interfect
  • 2,665
  • 1
  • 20
  • 35