5

I am trying to learn python (coming from PHP), and want to set up the simplest web server so I can start coding.

I found the integrated HTTP server, so I figured it should be the easiest way.

root@ubuntu:/var/py# python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...

The webserver is working, accessing http://test.dev:8000/test.py (thanks /etc/hosts) works - but shows me the contents of the file ( print('Hello world!'); ), without interpreting it.

How to properly set up the server / interpretor ?

1
  • Does test.py have executable ("+x") permission? Commented Jun 8, 2013 at 11:24

2 Answers 2

5

Python is for writing programs in general, not only web-sites.

SimpleHTTPServer is really just a trivial HTTP server, it serves files. It doesn't try to interpret code.

If you want to do web-development with Python, you should be using a web framework. web.py is a good choice, you can check its tutorial. Another option is Django, which also has a brilliant tutorial.

Both of them have simple development servers built in, so you'll be able to start experimenting easily.

Sign up to request clarification or add additional context in comments.

1 Comment

Gave it a try with Django, and it's working perfectly (the tutorial is brilliant :P)
2

If you are just starting out with python I would recommend you start with scripts that can be run from the console using python interpreter. (eg: python run1.py)

Once you have mastered the basics, you can move onto web programming. (I am guessing that you want to try web programming since you mention a web server.) In this case, you have multiple options (all of which work with Apache):

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.