I've recently been developing with Python, and I absolutely love it. It's a huge step up from PHP as a quick scripting language (imagine, no crazy function names!), and I would love to be able to use it as a web development language.
I've heard about Django, but I want something a bit more simple.
I run Lighttpd, and I've already gotten a Python script to work, but I can't pass arguments to it via the URL, like http://localhost/index.py?foo=bar. Is there a function/library that allows this?
I could be going at this all wrong, so please tell me if I am. But I absolutely hate PHP, now that I've seen Python. ;)
-
11Welcome to the light side.nmichaels– nmichaels2011年01月20日 21:09:15 +00:00Commented Jan 20, 2011 at 21:09
-
1So, any downsides to Python as a server language? Why does nobody use it if it's so awesome?Blender– Blender2011年01月20日 21:12:58 +00:00Commented Jan 20, 2011 at 21:12
-
1Lots of people use it. A year ago I had to beat away recruiters wanting me to do Django stuff with a stick (I think they've finally noticed I've been in a front end role for two years though).Quentin– Quentin2011年01月20日 21:15:52 +00:00Commented Jan 20, 2011 at 21:15
-
3@Blender people do use Python, but most everyone uses a framework because Python isn't so joined-at-the-hip to the web server as PHP isRafe Kettler– Rafe Kettler2011年01月20日 21:16:06 +00:00Commented Jan 20, 2011 at 21:16
-
3Python is used by many major companies, Google is doing lot of Python and also Facebook, initially when Facebook started they wanted something quick and fast so used PHP but now if you see Facebook Requirements for Software Engineer, they do list Python, C++, Java, PHP and Perl, so you should not decide power of any language by assuming that one company did not use it so its bad.Rachel– Rachel2011年01月20日 21:27:18 +00:00Commented Jan 20, 2011 at 21:27
7 Answers 7
If you want a dead simple but powerful framework, try Flask.
(Then learn some SQLAlchemy, and things will suddenly become even easier.)
3 Comments
Assuming you're using a CGI interface, the cgi module.
8 Comments
You can check out the so-starving project to see a simple application written in a variety of different python web frameworks, and choose one that you agree with!
I can't pass arguments to it via the URL, like .../index.py?foo=bar. Is there a function/library that allows this?
Any of the available Python frameworks allow you to custom-map your URL's to specific python functions. The above URL would look more like .../blog/foo/bar and your app would know what to do with the extra bits.
On a personal note, I second the recommendation for Flask - It's a great microframework for beginners as well as useful to pros working on small projects.
I've also fallen in love with the framework Pyramid, which is a bit more complex but suited very well for larger applications.
Comments
I can recommend Django very highly. It's not that complicated. What I think you're looking for at the moment, however, is http://webpy.org/ .
Comments
You can use CGI, but it's somewhat counterintuitive and pretty painful to work with (compared to the alternatives). If you'd like to ease that pain, I'd suggest using a framework. There are quite a few frameworks out there, the most popular being Django, Pylons, and a few others. You can see a full list here and decide for yourself.
If you're looking for something full-stack, Django. If you want something small, Flask, web2py, and a number of others work.
Comments
You can use WSGI which is a standard interface between web servers and Python web applications or frameworks. This tutorial is really helpful for getting started with WSGI. It includes parsing GET and POST requests (as you mentioned in the question).
1 Comment
I'm a bit surprised that noone has named Turbogears ( http://turbogears.org/ ) yet. It is fairly new, but has a lot of promise and I find it quite simple and easy to use. I haven't tried many others as thorrowly though so I might be missing out :)
I am going to check FLASK now though :P