1

Sorry, I am a new to Python.

Task:

There are some HTML pages, which calls a URL with some parameters. The Python script should be able to detect the html request and based on the parameter execute function

Webpages are present in /var/www/html/

Example: From index.html, if a button is pressed, it calls a URL - bcast.xml?mode=1 or bcast.xml?mode=2 Now there is no file bcast.xml

So the Python script should basically be constantly looking for any request from the web server (apache) and if the file name is bcast.xml, it should look for mode value and based on that it should execute some functions

Question:

I have no clue where to start even Google it, What should I be searching for or if anyone knows of a solution that would be great.

Thanks in advance

Homam
  • 17
  • 2

2 Answers2

0

I suggest using a framework to handle this. Check out flask.

Python Flask how to get parameters from a URL?

Also, for Flask to communicate with Apache, you'll need to use mod_wsgi.

tr0yspradling
  • 529
  • 1
  • 9
  • 20
0

The easiest way is to use some framework, for example Flask.

Install it using pip:

pip install flask

Use:

from flask import Flask, request

app = Flask(__name__)

@app.route("/api_url/", methods=["POST"])
def handle_api_requests():
    return str(request.form)

app.run()

In handle_api_requests function you can describe any logic you need have to handle api requests from your frontend.

Artsiom Praneuski
  • 2,259
  • 16
  • 24