python scripts for web

Discussion in 'Python' started by chip9munk@gmail.com, Oct 18, 2012.

  1. Guest

    Hello all!

    Please help me start learning about this thing. Sorry for my inexperience!

    Here is what I need to do: on some webpage (done in php, or any other different technology), user inputs some data, that data and the request then goes to the server where python scripts calculate something and return the result to the users end.

    Now, how do I do that server part, listening to requests, and calling python scripts?

    I googled about that but I do not understand if I should do that by CGI, Flask, mod_wsgi, or any other way... I know to little about that to understand what is the way to go. :/

    Please could you give me some info so that i know where I should start looking for my solution.

    Thanks in advance!
    , Oct 18, 2012
    #1
    1. Advertising

  2. Zero Piraeus Guest

    :

    On 18 October 2012 03:18, <> wrote:
    > Here is what I need to do: on some webpage (done in php, or any other
    > different technology), user inputs some data, that data and the
    > request then goes to the server where python scripts calculate
    > something and return the result to the users end.
    >
    > Now, how do I do that server part, listening to requests, and calling
    > python scripts?


    If I understand you correctly, what you're describing here is a
    webserver - i.e. Apache, nginx etc. I'm not sure why you'd want to
    write one of those if you're as inexperienced as you say.

    > I googled about that but I do not understand if I should do that by
    > CGI, Flask, mod_wsgi, or any other way... I know to little about that
    > to understand what is the way to go. :/


    These are all approaches to writing the software that the webserver
    hands the request off to, which is a different thing. If that's what
    you really meant to ask (how to write a script that processes a
    request and returns a response), then plain CGI might be the best
    place to start, if you're trying to get a handle on what's going on.

    Once you're happy that you understand how to build a plain CGI script,
    frameworks [like Flask] can be very useful ... and Flask is both
    lightweight and has good documentation, so it's not a bad choice for
    learning purposes.

    -[]z.
    Zero Piraeus, Oct 18, 2012
    #2
    1. Advertising

  3. Guest

    To explain, I am basically doing different algorithms and would like to make them work and be accessible as I mentioned in the example... and to add them to the functionality of a specific page... so I have experience in programming, just no experience in web development etc..

    On Thursday, October 18, 2012 9:57:58 AM UTC+2, Zero Piraeus wrote:
    >
    > If I understand you correctly, what you're describing here is a
    > webserver - i.e. Apache, nginx etc. I'm not sure why you'd want to
    > write one of those if you're as inexperienced as you say.
    > These are all approaches to writing the software that the webserver
    > hands the request off to, which is a different thing. If that's what
    > you really meant to ask (how to write a script that processes a
    > request and returns a response), then plain CGI might be the best
    > place to start, if you're trying to get a handle on what's going on.


    I understand how the lack of knowledge on my part can cause the unclarity of my question.
    I will give you an example. So let us say I create two simple python scripts, one does the sum of two numbers
    the other one does the multiplication. SO now I want to put these scripts on the server. Now let us say there is a web page that would like to use these scripts (do this calculation). How do I do a "program" that will listen for the requests
    from the web page and call the scripts on the request?

    > Once you're happy that you understand how to build a plain CGI script,
    > frameworks [like Flask] can be very useful ... and Flask is both
    > lightweight and has good documentation, so it's not a bad choice for
    > learning purposes.


    all the tutorials about flask are dealing wit creating the whole webpage inpython. I do not need to do that, I just need a service on the servers end... is flask still the way to go? Also flask does not support Python 3.x jet, would using cherryPy be a good idea?

    Thank you for the answers!
    , Oct 18, 2012
    #3
  4. Guest

    To explain, I am basically doing different algorithms and would like to make them work and be accessible as I mentioned in the example... and to add them to the functionality of a specific page... so I have experience in programming, just no experience in web development etc..

    On Thursday, October 18, 2012 9:57:58 AM UTC+2, Zero Piraeus wrote:
    >
    > If I understand you correctly, what you're describing here is a
    > webserver - i.e. Apache, nginx etc. I'm not sure why you'd want to
    > write one of those if you're as inexperienced as you say.
    > These are all approaches to writing the software that the webserver
    > hands the request off to, which is a different thing. If that's what
    > you really meant to ask (how to write a script that processes a
    > request and returns a response), then plain CGI might be the best
    > place to start, if you're trying to get a handle on what's going on.


    I understand how the lack of knowledge on my part can cause the unclarity of my question.
    I will give you an example. So let us say I create two simple python scripts, one does the sum of two numbers
    the other one does the multiplication. SO now I want to put these scripts on the server. Now let us say there is a web page that would like to use these scripts (do this calculation). How do I do a "program" that will listen for the requests
    from the web page and call the scripts on the request?

    > Once you're happy that you understand how to build a plain CGI script,
    > frameworks [like Flask] can be very useful ... and Flask is both
    > lightweight and has good documentation, so it's not a bad choice for
    > learning purposes.


    all the tutorials about flask are dealing wit creating the whole webpage inpython. I do not need to do that, I just need a service on the servers end... is flask still the way to go? Also flask does not support Python 3.x jet, would using cherryPy be a good idea?

    Thank you for the answers!
    , Oct 18, 2012
    #4
  5. Zero Piraeus Guest

    :

    On 18 October 2012 04:10, <> wrote:
    > I will give you an example. So let us say I create two simple python
    > scripts, one does the sum of two numbers
    > the other one does the multiplication. SO now I want to put these
    > scripts on the server. Now let us say there is a web page that would
    > like to use these scripts (do this calculation). How do I do a
    > "program" that will listen for the requests
    > from the web page and call the scripts on the request?


    That is exactly what a webserver does. Is there some reason you don't
    want to use e.g. Apache to handle the requests?

    -[]z.
    Zero Piraeus, Oct 18, 2012
    #5
  6. Guest

    On Thursday, October 18, 2012 10:42:56 AM UTC+2, Zero Piraeus wrote:
    > That is exactly what a webserver does. Is there some reason you don't
    > want to use e.g. Apache to handle the requests?


    no reason at all. so i guess the solution is much easier then I have anticipated.
    So i guess in that case i do not need cgi or anything?

    Thank you for clearing that out!
    , Oct 18, 2012
    #6
  7. Guest

    On Thursday, October 18, 2012 10:42:56 AM UTC+2, Zero Piraeus wrote:
    > That is exactly what a webserver does. Is there some reason you don't
    > want to use e.g. Apache to handle the requests?


    no reason at all. so i guess the solution is much easier then I have anticipated.
    So i guess in that case i do not need cgi or anything?

    Thank you for clearing that out!
    , Oct 18, 2012
    #7
  8. Zero Piraeus Guest

    :

    On 18 October 2012 05:22, <> wrote:
    > So i guess in that case i do not need cgi or anything?


    Assuming your scripts accept the request as sent and return an
    appropriate response, they are CGI scripts (unless there's some
    wrinkle in the precise definition of CGI that escapes me right now).

    > Thank you for clearing that out!


    No bother :)

    By the way: are you using Google Groups? It's just that I'm led to
    understand that it's recently started to misbehave [more than it used
    to], and your replies are addressed to both
    <> and <>,
    which is redundant.

    Or perhaps it always did that, and I've never noticed before ...

    -[]z.
    Zero Piraeus, Oct 18, 2012
    #8
  9. On Thu, Oct 18, 2012 at 8:22 PM, <> wrote:
    > On Thursday, October 18, 2012 10:42:56 AM UTC+2, Zero Piraeus wrote:
    >> That is exactly what a webserver does. Is there some reason you don't
    >> want to use e.g. Apache to handle the requests?

    >
    > no reason at all. so i guess the solution is much easier then I have anticipated.
    > So i guess in that case i do not need cgi or anything?
    >
    > Thank you for clearing that out!


    CGI is a protocol between Apache and your script. What you want to do
    is set up Apache to call your CGI scripts.

    BTW, you don't need to send to both comp.lang.python and python-list -
    they mirror each other.

    ChrisA
    Chris Angelico, Oct 18, 2012
    #9
  10. Guest

    On 10/18/2012 04:02 AM, Zero Piraeus wrote:> On 18 October 2012 05:22, <> wrote:
    >>[...]

    > By the way: are you using Google Groups? It's just that I'm led to
    > understand that it's recently started to misbehave [more than it used
    > to], and your replies are addressed to both
    > <> and <>,
    > which is redundant.


    When you post from Google Groups you will sometimes
    see a checkbox above the edit window that is a cc to
    the python mailing list (<>)
    which is checked by default.

    If you uncheck that, you'll stop the double posting.
    , Oct 18, 2012
    #10
  11. Guest

    On Thursday, October 18, 2012 12:02:40 PM UTC+2, Zero Piraeus wrote:

    > Assuming your scripts accept the request as sent and return an
    > appropriate response, they are CGI scripts (unless there's some
    > wrinkle in the precise definition of CGI that escapes me right now).


    yes, they are, but, I came under the impression that it is not the most elegant/fast way to do it... shouldn't the mod_wsgi be a better strategy?
    or am i mixing these therms?
    , Oct 18, 2012
    #11
  12. Guest

    thank you for the answer!

    On Thursday, October 18, 2012 12:03:02 PM UTC+2, Chris Angelico wrote:
    > CGI is a protocol between Apache and your script. What you want to do
    > is set up Apache to call your CGI scripts.




    yes, but as I have just answered to Zero, is using mod_wsgi a better strategy?
    , Oct 18, 2012
    #12
  13. Guest

    thank you guys for pointing the double posting issue out, I am having some issues with the news server i am using, so I am doing this via google.groups at the time! :)

    i think i managed to fix it
    , Oct 18, 2012
    #13
  14. Zero Piraeus Guest

    :

    On 18 October 2012 12:03, <> wrote:
    > yes, but as I have just answered to Zero, is using mod_wsgi a better strategy?


    WSGI would enable you to write a persistent application that sits
    around waiting for requests and returns responses for them as and
    when, as opposed to a simple CGI script that gets started each time a
    request comes in, and terminates once it's returned the response.

    So it's really about startup time - if your scripts are just doing
    something simple and quick, WSGI is likely overkill.

    -[]z.
    Zero Piraeus, Oct 18, 2012
    #14
  15. Guest

    On Thursday, October 18, 2012 11:10:45 PM UTC+2, Zero Piraeus wrote:
    > WSGI would enable you to write a persistent application that sits
    > around waiting for requests and returns responses for them as and
    > when, as opposed to a simple CGI script that gets started each time a
    > request comes in, and terminates once it's returned the response.


    ok I see, you have made it very clear for me now!

    > So it's really about startup time - if your scripts are just doing
    > something simple and quick, WSGI is likely overkill.


    these scripts will do a lot of calculation on a big dataset, and it is possible that there will be many requests in a short period of time.
    So I guess the WSGI is a better solution.

    Thank you and the others very much, you have saved me a lot of time!

    Cheers!
    , Oct 19, 2012
    #15
  16. Gilles Guest

    On Thu, 18 Oct 2012 23:05:48 -0700 (PDT), wrote:
    >these scripts will do a lot of calculation on a big dataset, and it is possible that there will be many requests in a short period of time.


    In that case, are you sure a web script is a good idea? If you're
    thinking web to make it easy for people to upload data, click on a
    button, and get the results back, you might want to write the UI in
    Python but write the number crunching part in a compiled language.
    Gilles, Oct 19, 2012
    #16
  17. Guest

    On Friday, October 19, 2012 12:32:48 PM UTC+2, Gilles wrote:
    > In that case, are you sure a web script is a good idea? If you're
    > thinking web to make it easy for people to upload data, click on a
    > button, and get the results back, you might want to write the UI in
    > Python but write the number crunching part in a compiled language.


    well actually I would like to separate the web interface with this API...
    that is why I would like to work on the server side and not think about the
    interface side.
    , Oct 23, 2012
    #17
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jan Danielsson
    Replies:
    8
    Views:
    610
    Mike Meyer
    Jul 22, 2005
  2. Jp Calderone
    Replies:
    0
    Views:
    443
    Jp Calderone
    Jul 21, 2005
  3. davidj411
    Replies:
    0
    Views:
    481
    davidj411
    Jun 27, 2008
  4. IronyOfLife
    Replies:
    7
    Views:
    443
    Gabriel Genellina
    Aug 11, 2009
  5. Replies:
    13
    Views:
    514
    Anno Siegel
    Sep 10, 2007
Loading...

Share This Page