Difference in coding for mod_python, CGI python, the regular python interpreter, etc

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hero Doug
    New Member
    • Nov 2006
    • 16

    #1

    Difference in coding for mod_python, CGI python, the regular python interpreter, etc

    I'm looking at Python and noticed that there's a few way's to use Python for web development.

    If I write some code for a system using mod_python will it run unaltered in CGI mode and from the interpreter? Or are modifications required? If so, how drastic?

    Thanks for your time.
  • oler1s
    Recognized Expert Contributor
    • Aug 2007
    • 671

    #2
    So, CGI is a specification, and part of it explains how CGI programs are written. CGI programs are just like ordinary programs on your computer. Can your computer run it? Then it can be made into a CGI. (Well, more accurately, it needs to be able to output to stdout or something, but those details go offtopic).

    Ok, it’s a bit more complicated than that. CGI programs, if you want them to be useful, need to deal with all the requirements of CGI. For one thing, the output needs to be formatted a certain way. Command line arguments are actually used by CGI for another purpose, so you rely on environment variables. Etc etc. You can google up “Python CGI”, “CGI”, and all those things, and they’ll teach you how to write CGIs. Obviously, the CGI tutorials designed specifically for Python will be easiest to understand.

    mod_python is different. It’s specifically for Apache, because what mod_python does is it integrates tightly with Apache and intercepts chosen requests. See, when a request for a webpage is made, Apache normally deals with it in several processing steps (phases). mod_python provides and allows you to provide handlers for various phases, in place of Apache’s. Kinda neat, as you aren’t limited to writing programs anymore. You can modify content, etc.. Of course, you can also use this capability to have Apache serve your python programs instead. mod_python is a generic system for having Python deal with handlers, and that’s why there’s more configuration work involved in getting mod_python to work with Python code.

    Comment

    • Hero Doug
      New Member
      • Nov 2006
      • 16

      #3
      Thanks for the reply oler1s.

      It seem's that python may not be the most web friendly when it come to setting up an environment.

      My biggest concern was knowing how portable the code I write would be. It would be ideal to use the code I write in a desktop app or on the web without modification.

      By the sounds of it using Python on the web shouldn't be too difficult. I'm thinking a specialized front-controller to access the business logic.

      Comment

      • oler1s
        Recognized Expert Contributor
        • Aug 2007
        • 671

        #4
        It seem’s that python may not be the most web friendly when it come to setting up an environment.
        True, that crown is fit for PHP. It was designed very much as a web-centric language, and everything from the language to setting up the environment (at least with an Apache based stack) is very easy.

        Python has gained a lot of popularity recently with the release of web frameworks like Turbogears and Django, and more. All these frameworks make web development very easy, and combat some of the (perceived?) problems with PHP. That and Python itself is a very beginner friendly language.

        If you’re looking to get into web development with Python, don’t discount the various web frameworks for Python. They are extremely powerful and of industrial strength.

        My biggest concern was knowing how portable the code I write would be. It would be ideal to use the code I write in a desktop app or on the web without modification.
        Careful, even if the code is technically portable, that doesn’t mean you would run it on the web directly. Aside from the more stringent security checks, you have to be aware that you are under the constraints of a web system. Your program can be called frequently, concurrently, etc. It needs to respond quickly to the user, and so on. None of these requirements are Python specific. They are just generic development guidelines for the web.

        Comment

        Working...