0

first, English is not my native language, so, forgive me for any mistake.

I don't want to make a evasive question, so i will detail my scenario and make my point below:

I need to make a Web interface to take a information from a html's form field. Specifically a text file. Then, i need to give this file as a paramater to a Python Script that will run on my Linux server (the same who was the Web interface). I have the script running okay, have the Web interface ready, but i didn't get the point to make the web stuff works.

I'm stuck on the part of "make the wweb form talks with python script". I tried some linux commands and some tips found on my research, but didn't work.

The goal of this thing, is to not send the Python code to end-user. So, the clients will "use" the code from a web interface and will not see the Python code responsable for make the hole stuff works.

Does anyone ever seen this kind of implementation?? Any help or information will be nice ! Tks a lot !

StarkBR
  • 227
  • 8
  • 15

1 Answers1

3

You should probably start with this page from the Python documentation - http://docs.python.org/howto/webservers.html. This may give you some ideas about how this works, and depending on what you need you may then continue reading about more detailed topics. Solution will depend on your plans for further development (will you extend the logic of this application? will you connect to the DB, etc.), security concerns, etc.

For only the case you define, it sounds like some simple solution will work for you, like having a simple CGI script ( http://docs.python.org/library/cgi.html), and you probably don't (yet) need anything powerful like Django or TurboGears.

For CGI to work, you will need to configure Apache web server, enable CGI for it, and then implement the CGI script utilizing your already implemented program.

You may check on the web how to do each of those steps. For example, right here, on stackoverflow: How do you set up Python scripts to work in Apache 2.0?

In your CGI script, you will need to implement some logic which will allow users to upload files to your server. You may check this page for that: http://code.activestate.com/recipes/273844-minimal-http-upload-cgi/

Finally, if with time you plan to further develop your application, you may want to look to something like Django or TurboGears. The more complex your application is - the better it is to use some web framework. You will probably spend more time studying those, but in the end you get much more power with them, and you get the code which is much more easier to maintain compared to CGI scripts. But, just as I said - it depends on your needs. (Although studying them is a good idea anyway ;) )

Community
  • 1
  • 1
Tim
  • 12,318
  • 7
  • 50
  • 72
  • 1
    Academically, learning how CGI works could be valuable. Practically, in the sense of getting to his goal, I think a *simple CGI script* is definitely more complex than a simple framework such as [Flask](http://flask.pocoo.org/) or [Pyramid](http://docs.pylonsproject.org/projects/pyramid/en/latest/?awesome#tutorials) – kojiro May 25 '12 at 18:09
  • Yep, I agree that writing CGI scripts is actually pretty confusing. Though, in fact this - http://code.activestate.com/recipes/273844-minimal-http-upload-cgi/ - already implements what StarkBR asks for :) – Tim May 25 '12 at 18:14
  • Ha! I actually never used Flask before, so I just checked out their documentation - it seems to be very simple indeed. Thanks for pointing that out! **Very interesting**. – Tim May 25 '12 at 18:23
  • I get the point. :) Thanks a lot for everybody ! – StarkBR May 25 '12 at 18:32
  • About the frameworks, they are really interesting. Tks for that too ! – StarkBR May 25 '12 at 18:34