1

I've an HTML Page which send value to a Python script. I want to receive the values of the data send and also ensure that the script is running everytime so as the data can received mutiple times. how would I do that?

My Jquery is

$(function(){
            $("#submit").click(function(){
                $.ajax({
                    dataType: "json",
                    type : "POST",
                    url: "/tcp_driver.py",
                    data : { 'count_query' : 'count_query', 'start_time' : start_time, 'end_time' : end_time, 'last_time' : last_time},

                    success : function(result){
                    }
                });
            });
        });

I want to connect my HTML page with a python code. How would I do that? How would I keep my python code listening? kindly guide me or point towards a resource where I can read on it. Thanks

Praful Bagai
  • 16,684
  • 50
  • 136
  • 267
  • You can search on net for **python webservice*, there are tool like DJango, WebPy, pecan etc.. available. Select which is comfirtable for you. – Nilesh Jul 26 '14 at 11:34
  • Cant I do it with single Python script? Is it a requirement for this particular use-case. – Praful Bagai Jul 26 '14 at 11:38
  • I'm reading about CGI scripts. Is it a solution for the same? PS: tried that but not working as per my requirements. – Praful Bagai Jul 26 '14 at 11:39
  • I am not aware about CGI bu u can use DJango its simple. https://docs.djangoproject.com/en/1.6/intro/tutorial01/ – Nilesh Jul 26 '14 at 11:40

1 Answers1

0

There are many python web frameworks such as Flask, Django. My recommendatian is to start with Flask Framework. It is very simple and easy to start.

from flask import Flask
app = Flask(__name__)

@app.route("/")
def index():
    return "Hello World!"

@app.route("/message")
def message():
    // Handle your post message
    return "Hello World!"


if __name__ == "__main__":
    app.run()
Fizer Khan
  • 88,237
  • 28
  • 143
  • 153
  • I dont want to use any frameworks. What I want is that there is one python code which should be listening all the times. How will I do that? – Praful Bagai Jul 26 '14 at 13:00
  • If you made this decision because of not knowing the frameworks, then i can strongly suggest you to learn some framework. If you have any other good reason not using frameworks, then you can checkout this stackoverflow question http://stackoverflow.com/questions/596729/how-do-i-use-python-for-web-development-without-relying-on-a-framework – Fizer Khan Jul 26 '14 at 14:17