Can't run python code in Apache

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • poppor
    New Member
    • Dec 2006
    • 6

    Can't run python code in Apache

    Hello!

    I posted below question in the "Python" forum and realized that maybe it should be in Apache forum instead ?

    Anyways, I appreciate any help...

    Thanks!
    /P

    ---------------
    Hi,

    I'm new to both Python and Apache so sorry for any upcoming
    dummy questions

    I'm running Linux (Ubuntu 6.10) and have installed the following:
    - Apache 2.0.55
    - Python 2.4.4c1
    - libapache2-mod-python

    One thing I'm still not clear about is if mod-python and CGI scripts are
    the same thing or not ? Because I think I've got it all mixed up. I don't
    think that mod-python is really needed to run python scripts or am I
    wrong ?

    Anyways, in /etc/apache2/apache2.conf I have the following lines
    AddHandler cgi-script .py
    <Directory /var/www>
    AddHandler mod_python .py
    </Directory>

    In the directory /var/www I have 2 files htmlgen.py and mypage.html

    File: htmlgen.py
    ------------------------
    import cgi

    print "Content-type: text/html\n\n"
    print "Testing... "

    File mypage.html
    --------------------------
    <form action="htmlgen .py" method="post">
    <input type="submit" value="Test">
    </form>

    Now when I open mypage.html I get a button saying "Test". When I press this button Firefox wants to download the file called htmlgen.py. Why? Apache is not running the file, just sending it.

    I hope someone can help me. I've read all documentation I could find but don't know what is wrong.

    Best Regards
    /P
  • sashi
    Recognized Expert Top Contributor
    • Jun 2006
    • 1749

    #2
    Originally posted by poppor
    Hello!

    I posted below question in the "Python" forum and realized that maybe it should be in Apache forum instead ?

    Anyways, I appreciate any help...

    Thanks!
    /P

    ---------------
    Hi,

    I'm new to both Python and Apache so sorry for any upcoming
    dummy questions

    I'm running Linux (Ubuntu 6.10) and have installed the following:
    - Apache 2.0.55
    - Python 2.4.4c1
    - libapache2-mod-python

    One thing I'm still not clear about is if mod-python and CGI scripts are
    the same thing or not ? Because I think I've got it all mixed up. I don't
    think that mod-python is really needed to run python scripts or am I
    wrong ?

    Anyways, in /etc/apache2/apache2.conf I have the following lines
    AddHandler cgi-script .py
    <Directory /var/www>
    AddHandler mod_python .py
    </Directory>

    In the directory /var/www I have 2 files htmlgen.py and mypage.html

    File: htmlgen.py
    ------------------------
    import cgi

    print "Content-type: text/html\n\n"
    print "Testing... "

    File mypage.html
    --------------------------
    <form action="htmlgen .py" method="post">
    <input type="submit" value="Test">
    </form>

    Now when I open mypage.html I get a button saying "Test". When I press this button Firefox wants to download the file called htmlgen.py. Why? Apache is not running the file, just sending it.

    I hope someone can help me. I've read all documentation I could find but don't know what is wrong.

    Best Regards
    /P
    Hi there,

    Kindly refer to below attached link for further reading & understanding, hope it helps. Good luck & Take care.

    Python and Apache2 (mod_python) configuration - step by step guide

    Comment

    • poppor
      New Member
      • Dec 2006
      • 6

      #3
      Originally posted by sashi
      Hi there,

      Kindly refer to below attached link for further reading & understanding, hope it helps. Good luck & Take care.

      Python and Apache2 (mod_python) configuration - step by step guide

      Thanks alot Sashi! Now I got it working!
      Regards
      /P

      Comment

      • sashi
        Recognized Expert Top Contributor
        • Jun 2006
        • 1749

        #4
        Originally posted by poppor
        Thanks alot Sashi! Now I got it working!
        Regards
        /P
        Hi there,

        Good luck to you. Take care.

        Comment

        Working...