Python to handle HTTP Request











up vote
0
down vote

favorite
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










share|improve this question




























    up vote
    0
    down vote

    favorite
    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










    share|improve this question


























      up vote
      0
      down vote

      favorite
      1









      up vote
      0
      down vote

      favorite
      1






      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










      share|improve this question















      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







      python html web






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 at 2:22









      Homam

      192




      192










      asked Nov 13 at 22:54









      Hari Haran T

      82




      82
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          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.






          share|improve this answer




























            up vote
            0
            down vote













            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.






            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290734%2fpython-to-handle-http-request%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              0
              down vote













              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.






              share|improve this answer

























                up vote
                0
                down vote













                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.






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  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.






                  share|improve this answer












                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 13 at 23:00









                  tr0yspradling

                  1831619




                  1831619
























                      up vote
                      0
                      down vote













                      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.






                      share|improve this answer

























                        up vote
                        0
                        down vote













                        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.






                        share|improve this answer























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          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.






                          share|improve this answer












                          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.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 13 at 23:06









                          Artsiom Praneuski

                          1,004312




                          1,004312






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290734%2fpython-to-handle-http-request%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              How to send String Array data to Server using php in android

                              Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

                              Is anime1.com a legal site for watching anime?