Web programming in Python.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kurda Yon

    Web programming in Python.

    Hi,

    I am totaly newbie in the Python's web programming. So, I dont even
    know the basic conceptions (but I have ideas about php-web-
    programming). Does it work in a similar way? First, I have to install
    a Python-server?

    On the server where I have my web site (it runs under Linux) if I type
    "python" I get the Python command line. Does it mean that I already
    have everything what I need to start web programming in Python. Should
    I give *.py extension to the Python programs?

    I tried the simplest what could I imagine. And it does not work. I
    have created a file "test.py" which contains
    print "Hello, World!"

    If I type "python test.py" it works! But, if I put in the address line
    of my browser "www.mydomainna me.org/test.py" it does not work. Or, to
    be more precisely, in my browser I see the content of the
    "test.py" (not the result of the execution).

    Could you pleas help me to start?

    Thank you !
  • Kurda Yon

    #2
    Re: Web programming in Python.

    1. On my server (in my directory) I found "cgi-bin" subdirectory.

    2. In the "cgi-bin" I have created a file "test.py".

    3. In that file I put:
    #!/usr/bin/python2.4 python
    print "Hello, World!"
    (I have checked, I have "/usr/bin/python2.4" directory.)

    4. I give the following permissions to the "test.py":
    -rwx---r-x

    5. The "cgi-bin" directory has the following permissions:
    drwx---r-x

    6. In the "cgi-bin" I have created the ".htaccess" file which
    contains:
    Options +ExecCGI
    AddHandler cgi-script .py


    And it still does not work! If I try to see the page by my browser I
    see:
    Internal Server Error
    The server encountered an internal error or misconfiguratio n and was
    unable to complete your request.
    ....

    Comment

    • Michael Crute

      #3
      Re: Web programming in Python.

      On Sun, Sep 28, 2008 at 6:39 PM, Kurda Yon <kurdayon@yahoo .comwrote:
      I am totaly newbie in the Python's web programming. So, I dont even
      know the basic conceptions (but I have ideas about php-web-
      programming). Does it work in a similar way? First, I have to install
      a Python-server?
      There are a couple of different ways to do web development in python.
      The easiest if you're familiar with web development in other languages
      is through CGI. I would recommend reading up on the python cgi module
      [1] which will walk you through the basics of writing your first cgi
      program. When you're comfortable with basic cgi you might want to look
      into a framework like Django or CherryPy.

      -mike

      [1] http://docs.python.org/lib/module-cgi.html

      --
      _______________ _______________ __
      Michael E. Crute


      God put me on this earth to accomplish a certain number of things.
      Right now I am so far behind that I will never die. --Bill Watterson

      Comment

      • Sean DiZazzo

        #4
        Re: Web programming in Python.

        On Sep 28, 4:51 pm, Kurda Yon <kurda...@yahoo .comwrote:
        1. On my server (in my directory) I found "cgi-bin" subdirectory.
        >
        2. In the "cgi-bin" I have created a file "test.py".
        >
        3. In that file I put:
        #!/usr/bin/python2.4 python
        print "Hello, World!"
        (I have checked, I have "/usr/bin/python2.4" directory.)
        >
        4. I give the following permissions to the "test.py":
        -rwx---r-x
        >
        5. The "cgi-bin" directory has the following permissions:
        drwx---r-x
        >
        6. In the "cgi-bin" I have created the ".htaccess" file which
        contains:
        Options +ExecCGI
        AddHandler cgi-script .py
        >
        And it still does not work! If I try to see the page by my browser I
        see:
        Internal Server Error
        The server encountered an internal error or misconfiguratio n and was
        unable to complete your request.
        ...
        Your server logs are your friend. Check /var/log/httpd/error.log for
        errors.

        Have you loaded the modpython module in your httpd.conf?

        ~Sean

        Comment

        • Lawrence D'Oliveiro

          #5
          Re: Web programming in Python.

          In message
          <2afd3f2f-8b80-4a99-965a-6e27f7000055@r1 5g2000prh.googl egroups.com>, Sean
          DiZazzo wrote:
          Have you loaded the modpython module in your httpd.conf?
          Not relevant for CGIs.

          Comment

          • Paul Boddie

            #6
            Re: Web programming in Python.

            On 29 Sep, 01:51, Kurda Yon <kurda...@yahoo .comwrote:
            1. On my server (in my directory) I found "cgi-bin" subdirectory.
            >
            2. In the "cgi-bin" I have created a file "test.py".
            >
            3. In that file I put:
            #!/usr/bin/python2.4 python
            print "Hello, World!"
            (I have checked, I have "/usr/bin/python2.4" directory.)
            What's the spare "python" for at the end of the first line? You should
            also try and run the program directly just to see whether it runs and
            what it prints.
            4. I give the following permissions to the "test.py":
            -rwx---r-x
            >
            5. The "cgi-bin" directory has the following permissions:
            drwx---r-x
            This is probably acceptable.
            6. In the "cgi-bin" I have created the ".htaccess" file which
            contains:
            Options +ExecCGI
            AddHandler cgi-script .py
            >
            And it still does not work! If I try to see the page by my browser I
            see:
            Internal Server Error
            The server encountered an internal error or misconfiguratio n and was
            unable to complete your request.
            ...
            Read the error log, possibly found in a log directory in your home
            directory (since you seem to be in a hosting environment, but you'd
            look in /var/log/httpd or /var/log/apache for a system-wide Web server
            installation) and see what the complaint is. You might also consider
            looking at the following page for guidance:



            Paul

            Comment

            • Steve Holden

              #7
              Re: Web programming in Python.

              Kurda Yon wrote:
              1. On my server (in my directory) I found "cgi-bin" subdirectory.
              >
              2. In the "cgi-bin" I have created a file "test.py".
              >
              3. In that file I put:
              #!/usr/bin/python2.4 python
              OK, if /usr/bin/python2.4 really *is* a directory then you will need to
              make that first line

              #!/usr/bin/python2.4/python

              (The phrase folowing the "#!" should be a reference to your Python
              interpreter).
              print "Hello, World!"
              Also, this isn't going to be adequate as an HTTP response, which a CGI
              script is always supposed to provide. A minimal example would have a
              single header followed by a blank like (which marks the end of the
              headers) and your content, like this:

              print """Content-Type: text/plain

              Hello, World!
              """
              (I have checked, I have "/usr/bin/python2.4" directory.)
              >
              4. I give the following permissions to the "test.py":
              -rwx---r-x
              >
              5. The "cgi-bin" directory has the following permissions:
              drwx---r-x
              >
              6. In the "cgi-bin" I have created the ".htaccess" file which
              contains:
              Options +ExecCGI
              AddHandler cgi-script .py
              >
              >
              And it still does not work! If I try to see the page by my browser I
              see:
              Internal Server Error
              The server encountered an internal error or misconfiguratio n and was
              unable to complete your request.
              ...
              --

              >
              If that doesn't get your script working then you should look at the
              error logs.

              regards
              Steve
              --
              Steve Holden +1 571 484 6266 +1 800 494 3119
              Holden Web LLC http://www.holdenweb.com/

              Comment

              • afrogazer

                #8
                Re: Web programming in Python.

                Not to be a condescending, but there are a lot of manuals out there on
                how to do this and asking on a forum would really not be the best way
                to get started. Do some research and some reading and you should be up
                and running in a short time. You can ask questions on the forum if you
                have difficulties while/after reading.

                Good luck



                Comment

                Working...