Python response to JavaScript
Question: I have an AJAX request to my Python file like so

    
    
    $ajax({
        type: "post",
        url: " name.py",
        data: { param: "hello" }
    }).done(function(obj){
        alert(obj);
    });
    

I want to get that request from my Python file and send a response to it -
"world".

But, I can't use the library Requests.

Please help me do this without using the library Requests

Can also use a different way in the JavaScript code.


Answer: You don't need `requests` for that, you need an HTTP server.

Flask is a simple web framework, it embeds his own HTTP server.

Here is a basic example on how to answer an http request, using flask :

    
    
    # main.py
    from flask import Flask
    app = Flask(__name__)
    
    @app.route("/")
    def index():
        return 'Hi'
    
    @app.route("/hello")
    def hello():
        return "Hello World!"
    
    if __name__ == "__main__":
        app.run()
    

Install flask using pip:

    
    
    python -m pip install flask
    

Then simply run your application development server using python :

    
    
    python main.py
    

And visit :

    
    
    http://[YOUR SERVER IP]/
    and 
    http://[YOUR SERVER IP]/hello
    

