You are invited to Log in or Register a free Frihost Account!

Is there a Python Hello World using Apache?

Echo Printer
Hi everyone, I am just beginning to learn some Python and would like to know how/if I am able to embed Python into a simple HTML file and have it display in my browser if I point it to the correct directory....that's sounds confusing, I know.
For example, in PHP to print out a simple Hello World in Mozilla Firefox I could enter the following code into a file (of course, the file would have to have a .php extension):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" >
    <title>Untitled Page</title>
  // Hello World in PHP
  echo 'Hello World!';

So, after I create this php file I could place it my www or htdocs inside my Apache folder (I am doing all of this locally), then simply enter http://localhost/hello.php into Firefox and it would print out my nice little Hello World!

So, how would you do the same thing, but with Python? I see there's a cgi-bin and I am wondering if Python uses that folder like Perl would. If that's the case could someone skilled in Python write out a small Hello World in Python (have it embedded in a HTML file so I can see exactly how it's done)?
If I could do this it would make things come together a little faster for me. Any help would be greatly appreciate. If you need any more information just email me. Thanks in advance!
...after the last couple of hours (i forgot to mention that am working on Windows machine which makes thngs much Linux things are much easier using Apache (cgi) in my opinion.) I see that it must be something the httpd.conf file...something along the lines of the ScriptAlias, but I've tried a few different things and it just isn't working. One peculiar thing happens though, when I run the sample Perl file inside the cgi-bin folder (http://localhost/cgi-bin/, it runs the script with no problem after i change the she-bang line to #!C:\Perl\bin\perl.exe. But if I write a simple Hello world program it give me the Internal Server Error page....strange....if I could get Perl to work, then I think I could get Python to start working as well. So, any suggestion on getting Perl scripts working on a Windows XP machine with Apache Web Server installed and ActiveState's Perl installed as well? ..that's all for now...
Okay, after all morning and afternoon spent trying to find out how to run Python CGI script I've learned a few, if you want the best solution in my opinion go with Apache and use the mod_python extension, but be prepared to go through hell. But if you're just learning about Python and just simply are curious like I was, pick up O'Reilly's Programming Python and in the source code that comes along with the book, there's a cool, simple web server coded in Python that can be ran on the same local machine as your browser.....whew!!!! enough of that.... Shocked

#!/usr/bin/env python

print "Content-Type: text/plain\n\n"
print 'Hello, world!\n'

just run it as cgi file.
deepak wrote:

just run it as cgi file.

You missed the point:

Echo Printer wrote:

Hi everyone, I am just beginning to learn some Python and would like to know how/if I am able to embed Python into a simple HTML file and have it display in my browser

Here is a mod_python hello world:
Related topics
Running a "Hello World" php script
hello world
Hello World!
Running ASP && ASP.NET -> APACHE
::Hello, World::
Basic VB Tutorial - "Hello World"
4 Java Tutorials (Have added a new one.)
Nine-year-old writes hit iPhone app
Hello World
Hello, world
Python hello world
displaying Hello world
Hello world
Reply to topic    Frihost Forum Index -> Scripting -> Others

© 2005-2011 Frihost, forums powered by phpBB.