diff options
Diffstat (limited to 'wired/old/published/Webmonkey/Frameworks/django-overview.txt')
-rw-r--r-- | wired/old/published/Webmonkey/Frameworks/django-overview.txt | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/wired/old/published/Webmonkey/Frameworks/django-overview.txt b/wired/old/published/Webmonkey/Frameworks/django-overview.txt new file mode 100644 index 0000000..7856231 --- /dev/null +++ b/wired/old/published/Webmonkey/Frameworks/django-overview.txt @@ -0,0 +1,87 @@ +Django is web framework written in Python and design to help you build complex web applications simply and quickly. If you're familiar with Ruby on Rails, think of Django as Rails for Python. It might not be technically correct, but it captures the basic idea. + +Django was designed from the ground up to handle two common web developer challenges: intensive deadlines and strict adherance to the [http://c2.com/cgi/wiki?DontRepeatYourself DRY principle]. + +The results are framework that's fast, nibble and capable of generating full site mockups in no time at all. Django's slogan captures it's essence quite nicely: The web framework for perfectionists with deadlines. + +Bu quick doesn't mean sloppy, Django comes with a very slick built-in Admin section for administering sites, support for a variety of cacheing options, including memcached, and a host of other stable, scalable tools. + +But perhaps the best part about Django is its outstanding documentation. Unlike many open source projects, Django has [http://www.djangoproject.com/documentation/ very thorough and readable docs available online]. If you have any problems with our tutorials head over to the Django site for additional reading. Also consider joining the [http://groups.google.com/group/django-users django-users Google Group] which is full of helpful folks who can point you in the right direction. + +== Why Isn't Django a 1.0 Release? == + +As of this writing Django has not yet released an official 1.0 version. The tenative schedule calls for Django 1.0 to arrive in September 2008, though that is subject to change. However both Django .95 and .96 are stable -- if not feature-complete -- releases. + +That said, the best way to use Django is working off the current trunk by doing a Subversion checkout. This will give you access to the latest and greatest tools and improvements and, unlike many projects, the Django trunk is remarkably stable. + +I've been using Django for two years on a number of production sites all built using Django trunk checkouts and have yet to encounter a bug or other issue. + +Of course the fact that Django doesn't have a 1.0 release will make some developers nervous and the Django team is aware of that. Django is close to 1.0 and work is progressing everyday toward that release, but remember all that stuff about perfectionists? It isn't just a slogan. + +The Django devs are probably tired of explaining themselves by now, but on the bright side you can rest assured that when 1.0 does arrive it's going to be rock solid. +== Background == + +Before we dive in it's worth pausing for a moment to understand where Django comes from, which has influenced both what it is and what it is not. + +Django was developed over a two year period by programmers working for an online-news operation (World Online in Lawrence Kansas). Eventually the team realized that they had a real framework on their hands and released the code to the public under an open source BSD license. + +Once it became a community project the development took off and Django began to pop up all over the web. For a complete list of Django sites check out [http://www.djangosites.org/ Django Sites], but notable examples include [http://pownce.com/ Pownce, [http://projects.washingtonpost.com/congress/ The Washington Post] and [http://everyblock.net/ Everyblock]. + +Perhaps the most common misconception is that Django is a content management system. It's not. It's a [http://www.webmonkey.com/tutorial/Get_Started_with_Web_Frameworks framework] and it can be used to build a CMS, but it isn't like Drupal or other CMS systems. + +Django is designed to work in slightly modified Model-View-Controller (MVC) pattern. The original Django developers refer to Django as an "MTV" framework — that is, "model", "template", and "view." + +The central difference is that in Django's version of MVC development the view refers to the data that gets presented to user -- not ''how'' it looks, but ''which data''. In other words, to quote the Django documentation, "the view describes which data you see, not how you see it." + +It's a subtle, but important difference and it explains the additional element -- templates -- which handle how the data looks. + + +== Overview == + +Django was designed to make web development fast and easy, dare I even say fun. And when I say fast I mean it, once you're comfortable with Django it's not hard to go from simple wireframe to working demo site in an hour or so. + +For development purposes Django is entirely self-contained. It includes a command line interface, a web server and everything you need to get up and running without installing anything other than Django. + +That said, the web server included with Django is not intended to be used in a production environment. For that the prefered method is to run Django through mod_python or mod_wsgi. Don't worry we'll get to that in a minute, but first let's look at how you might go about building a Django application. + +As it turns out, building a Django app actually takes much less time than explaining how to build it. + +Before we dive in though, it's worth asking, what do you mean by Django app? Django's official documentation and many of its built-in tools are set up to create projects (think of this a container for your whole site) and then within projects you have many apps (section of your site). + +Note that apps don't need to be in projects though and in many cases it's better not to put them there. + +For the sake of example here's a very high-level overview of building a Django app: + +# Create a project using the built in command line tool (<code>python django-admin.py startproject projectname</code>). This will generate a new folder containing the project's base settings file which you can use to specify database connections, template locations and more, urls.py which defines your base urls, manage.py which contains a standard set of command line tools. +# The next step is to create an app using the built in command line tool <code>python manage.py startapp appname</code>. + +Once the app folder is in place, it you look inside you'll see three files: models.py, urls.py and views.py. These are the files you'll use to actually build the app: + +# design your model (models.py) +# write your URLs (urls.py) +# create your views (views.py) +# build your templates + +Django includes it's own template language, although, as with many elements of Django, it's entirely optional. You can drop in another template language if you like, though you might want to give Django's a try first. It's simple, fast and already there. + +The other thing to keep in mind is that Django is written in Python and requires Python 2.3 or higher. Mac OS X and most Linux distros ship with Python 2.5 so that isn't a problem. Windows users may need to install Python. + +== So just how does Django work? == + +The simplest way to look at Django is to break it down into it's component parts. First off there's a models.py file which defines all your data model and extrapolates your single lines of code into full database tables and a pre-built (totally optional) administration section to add content. + +The next element is the urls.py file which uses regular expressions to capture url patterns for processing. + +The actual processing happens in your views, which, if you haven't seen the pattern yet, live in views.py. This is really the meat of Django, since views are where you grab the data that that you're presenting to the visitor. + +Here's what happens when a visitor lands on your django page: + +First Django consults the various URL patterns you've created and uses that information to retrieve a view. The view then processes the request, querying your database if necessary and passes the requested information on to your template. The template then renders the data in layout you've created and displays the page. + +== Dive in == + +Now that you have at least some idea of how Django works, it's time to dive in and get your hands dirty. For the sake of example we'll be building a blog-type site. It makes a nice intro to Django and takes advantage of some of Django's handy shortcuts and other features. + +But don't worry we aren't going to just build a blog, we'll also walk through adding a contact form, static pages (like an 'about' page) and even integrate Django with del.icio.us web services to display all your del.icio.us links on your new Django blog. + +So head on over to part two of our intro to Django [Installing Django and Building Your First App]
\ No newline at end of file |