views:

604

answers:

9

I have been doing some work in python, but that was all for stand alone applications. I'm curious to know whether any offshoot of python supports web development?

Would some one also suggest a good tutorial or a website from where I can pick up some of the basics of web development using python?

A: 

Lookup Django.

Clint Miller
A: 

Python can be used for web development, but there isn't a special language extension or anything in the language that will handle all the HTML generation or that works like PHP.

It's pretty much run through some sort of interpreter on a web server (CGI, mod_python, etc.).

I would recommend looking into Python Web Application Frameworks or how to write Python CGI scripts.

Jesse Dearing
+2  A: 

Python Wiki: Web Frameworks for Python

If you decide to use Django, the official tutorial is an excellent place to start. The Django Book is also free.

Imran
A: 

There are quite a few web frameworks for python out there, but the only one I've used is Django, and I really like it.

If you've got a few hours, do the tutorial, I promise you, you'll enjoy it :)

Adrian Mester
+1  A: 

Don't lookup Django until you have a good grasp of what Django is doing on your behalf. for you. Write some basic apps using mod_python and it's request object. I just started learning Python for web-development using mod_python and it has been great.

mod_python also uses a dispatcher in site-packages/mod_python/publisher.py. Have a ganders through this to see how requests can be handled in a simple-ish way.

You may need to add a bit of config to your Apache config file to get mod_python up and running but the mod_python site explains it well.

<Directory /path/to/python/files>
     AddHandler mod_python .py
     PythonHandler mod_python.publisher
     PythonDebug On
</Directory>

And you are away!

use (as a stupidly basic example):

def foo(req):
    req.write("Hello World")

in /path/to/python/files/bar.py assuming /path/to is your site root.

And then you can do

http://www.mysite.com/python/files/bar/foo

to see "Hello World". Also, something that tripped me up is the dispatcher uses a lame method to work out the content-type, so to force HTML use:

req.content_type = 'text/html'

Good Luck

After you have a good idea of how Python interacts with mod_python and Apache, then use a framework that does all the boring stuff for you. Up to you though, just my recommendation

Aiden Bell
If you insist on suggesting that people roll their own, you should at least suggest that they use WSGI and not mod_python. WSGI is the standard for writing python web apps and does not lock you in to the API of a specific webserver (as common as that webserver may be). Furthermore, as you discover some of the pain of writing a webapp from scratch WSGI leaves the door open to reuse other WSGI components.
Aaron Maenpaa
Given that the OP is used to standalone development in Python, and requested "basics of web development using python" this seemed like the appropriate place to start, having started this way myself and found it a great foundation to build on.
Aiden Bell
A: 

As others have mentioned, one of the more prominent python "offshoots" as you call them would be Django. It is a rather powerful framework that allows you to quickly and securely build web applications. The first place to look would be their overview which gives some insight as to what Django does as a framework.

Going through their tutorial taught me alot about the prominent Model-View-Controler design pattern and how it may be used in a web-development context. I found it a great way to start writing an application that worked and learn by improving it.

Daniel Gill
+2  A: 

If you really don't want to delve into the frameworks - and you should, I heartily recommend Django or Pylons - there's still need to go down the road of CGI. This is a totally out-of-date technology, not to mention slow and inefficient.

There is a standard way of building Python web applications, and it's called WSGI. If you want to roll your own web app from scratch, this is absolutely the way to go.

That said, if you're just starting out, really you should go with one of the frameworks.

Daniel Roseman
+9  A: 

Now that everyone has said Django, I can add my two cents: I would argue that you might learn more by looking at the different components first, before using Django. For web development with Python, you often want 3 components:

  1. Something that takes care of the HTTP stuff (e.g. CherryPy)

  2. A templating language to create your web pages. Mako is very pythonic and works with Cherrpy.

  3. If you get your data from a database, an ORM comes in handy. SQLAlchemy would be an example.

All the links above have good tutorials. For many real-world use-cases, Django will be a better solution than such a stack as it seamlessly integrates this functionality (and more). And if you need a CMS, Django is your best bet short of Zope. Nevertheless, to get a good grasp of what's going on, a stack of loosely coupled programs might be better. Django hides a lot of the details.

stephan
+1 SQLAlchemy is very cool (though, django+etc have the benefit of already picking the dispatcher, ORM, Template language so that you don't have to).
Aaron Maenpaa
@Aaron: totally, agree. Amended answer to make this advantage of Django clearer
stephan
+1  A: 

There are a couple of choices for web development. From my experience, your choice will again be dependent on your application. I used django and web.py in production and I am about to deploy an app based on pylons.

Django hides a lot of choices (comes with its ORM and templating). The documentation is extensive and well-written. There are many reusable app available for django, but you will likely to invest a little time in integrating them seamlessly. One thing mentioned on djangocon 08 was the fact, that there is cool stuff in django, which can't be easily accessed in non-django projects.

web.py impressed me by its raw simplicity. Before I knew it, I wrote a small app (78 lines quasi-wiki) in it.

pylons feels like in the middle of both. I can use sqlalchemy and jinja, all in all a pleasant experience for the start.

The MYYN