Web programming in Python.

K

Kurda Yon

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.mydomainname.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 !
 
K

Kurda Yon

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 misconfiguration and was
unable to complete your request.
....
 
M

Michael Crute

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
http://mike.crute.org

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
 
S

Sean DiZazzo

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 misconfiguration 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
 
P

Paul Boddie

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 misconfiguration 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:

http://wiki.python.org/moin/CgiScripts

Paul
 
S

Steve Holden

Kurda said:
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 misconfiguration 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
 
A

afrogazer

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top