This post shows how to setup a python web development environment under Ubuntu and make a hello world example.
So Python has become a hot word in recent years. But before you can do anything about it, you need a “hello world” sample application. In this post, I will build a hello world Python web application under Ubuntu.
1. Install Apache server. This is the web server that will handle HTTP requests.
Try the following command and and open a browser and type “localhost”, if server is up go to step 2.
If server is not running, use the following command to install:
2. Install mod_python. This is the module that is used to process .py files.
3. Configure Apache server. (If you configure PHP on Apache server, this is almost the same)
Even now you have installed mod_python in step 2, Apache server does not know how to handle .py files. We need to add a handler to
(you need to be in sudo mode to be able to edit “default” file!)
4. Write your “hello world” program.
def index(req): return "Hello World"; |
It looks like the following, and be careful about indentation.
5. Restart Apache server and run your first Python web application.
You should be able to get your “hello world” web app correctly running.
Congratulations!
You can now start exploring Python world, either by reading a book or google search!
Probably you created a file named index.py in step :
sudo vi /var/www/index.py
And in web browser you tried to use test.py.
Try to use index.py or rename in to test.py 🙂
Hey.. I follow the procedure on 12.04…. But after following the procedure.. when I write localhost/test.py in browser… it says to me open the file or download it