The Artima Developer Community
Sponsored Link

Java Community News
An Introduction to Django

1 reply on 1 page. Most recent reply: Apr 25, 2008 5:56 AM by Berco Beute

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

An Introduction to Django Posted: Apr 23, 2008 8:25 PM
Reply to this message Reply
Summary
When Google introduced its AppEngine service, it announced that Python would be the service's first supported language. One of the most important Python Web frameworks that can easily be hosted on AppEngine is Django. Dan Ellis introduces Django in a recent article.
Advertisement

While a great deal of attention has been devoted to Ruby and Java Web frameworks, many Python developers have been busy developing Django, an open-source Web application and content management framework. In many ways, Django provides similar features to Rails, except that it relies on the Python language, and also aims for greater extensibility.

Similar to Rails, Django was also extracted from a real-world Web application, writes Dan Ellis in a recent article, Introduction to Django: Helping Perfectionists With Deadlines.

In the article, Ellis provides a high-level overview of Django, focusing on the framework's three main components: its data model, view, and URL mapping:

Like other frameworks, Django uses a model-view-controller paradigm where your data model, logic, and presentation are separated. Your logic is written in Python and your presentation is written as templates (typically HTML, but they can be any textual format). Although your data is stored in a relational database (Postgres, MySQL, Oracle, and SQLite are all supported), Django actually lets you define your data model using Python classes, then lets you manipulate your data using those classes...

For a typical working application you need to create three things: a data model, at least one view, and a URL mapping... Django’s object-relational mapping will automatically translate between Python objects and the appropriate SQL statements to query and manipulate the database... You get the option of using your own SQL queries if you need to, but this will rarely be the case since Django can elegantly construct complex queries for you...

Ellis points out that while Django allows you to use Python in its templates, most Django templates tend to be very view-centric, and do not encourage mixing code into the presentation:

Django provides a template system that allows you to format your data as HTML... [Tokens] that look like {{this}} are variables, and the ones that look like {% this %} are blocks. In this example, customer is a variable that will be given to the template when it is rendered, so {{customer.cart.all}} becomes the contents of the customer’s cart... Django provides dozens of tags and filters as standard, and if you know your way around Python you can add your own.

One of the most interesting aspects of Django is its URL mapping facility that, similar to Rails, provides out of the box RESTful URLs:

It is the URL mappings that determine which view will be used. For example, you might decide that `/` is handled by a view called `index`, and `/products/` is handled by a view called `all_products`. It gets really interesting when you start using arguments. Instead of having a URL like `http://example.com/display_product.php?product=123` (which, let’s face it, is just plain ugly) you can have a URL like `http://example.com/products/123/` and have Django use the `product_detail` view with an argument of “123”. You are then free to pull product 123 out of the database and create an HTML page with information about it...

In the article, Ellis also points out the many useful modules and add-ons to Django, such as its administration interface:

One of Django’s most useful and impressive features is that it will dynamically create an entire admin system based on your data model(s). All you need to do is enable it and decide what URL you want to point there—then go ahead and manage your data!...

Another feature Ellis describes is Django's support for internationalization:

One is internationalization, which is an important and tricky topic that site developers are becoming more and more aware of. If you mark your text strings in your code and templates as being translatable, Django’s make-messages utility will create a translation file for all those strings. These are simple text files that you can have your translators fill in.

When it comes to displaying a page to the user, the language selection is made automatically. If the browser states the user’s preferred language and there is a translation for that language, that one is used, otherwise the configured default is used.

If you've tried Django already, how would you compare it to other Web frameworks, especially to Rails, in terms of its developer-friendliness and features?


Berco Beute

Posts: 72
Nickname: berco
Registered: Jan, 2002

Re: An Introduction to Django Posted: Apr 25, 2008 5:56 AM
Reply to this message Reply
Django is extremely user friendly imho. Python is of course the most readable language around, Django is very well thought out and feature rich, the documentation is top notch and the Django community is very friendly and helpful. What more could a developer wish for?

Although you can't translate your Django applications to Google AppEngine directly (in time you will), this is definitely the time to start learning Python and Django.

It is indeed springtime for both Python & Django. And it is well-deserved.

2B

Flat View: This topic has 1 reply on 1 page
Topic: JetGroovy 1.5 for IntelliJ IDEA Previous Topic   Next Topic Topic: Visualizing Concurrency

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use