Home Web Development Django 1.0 Website Development

Django 1.0 Website Development

books-svg-icon Book
eBook $25.99 $17.99
Print $43.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $25.99 $17.99
Print $43.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Introduction to Django
About this book
Django is a high-level Python web framework that was developed by a fast-moving online-news operation to meet the stringent twin challenges of newsroom deadlines and the needs of web developers. It is designed to promote rapid development and clean, pragmatic design and lets you build high-performing, elegant web applications rapidly. Django focuses on automating as much as possible and adhering to the DRY (Don't Repeat Yourself) principle, making it easier to build high-performance web applications faster, with less code. This book will show you how to assemble Django's features and take advantage of its power to design, develop, and deploy a fully-featured web site. It will walk you through the creation of an example web application, with lots of code examples. Specially revised for version 1.0 of Django, the book starts by introducing the main design concepts in Django. Next, it leads you through the process of installing Django on your system. After that, you will start right away on building your social bookmarking application using Django. Various Django 1.0 components and sub-frameworks will be explained during this process, and you will learn about them by example. In each chapter, you will build one or more of the features that are essential in Web 2.0 applications, like user management, tags, and AJAX. You will also learn about good software development practices, such as keeping your application secure, and automating testing with unit tests. By the end of the book, you will have built a fully functional real-life Web 2.0 application, and learned how to deploy it to a production server.
Publication date:
March 2009
Publisher
Packt
Pages
272
ISBN
9781847196781

 

Chapter 1. Introduction to Django

Welcome! This book is about Django, an open source web framework that enables you to build clean and feature-rich web applications with minimal time and effort. Django is written in Python, a general purpose language that is well-suited for developing web applications. Django loosely follows a model-view-controller design pattern, which greatly helps in building clean and maintainable web applications.

This chapter gives you an overview of the technologies used in this book. The chapters that follow will take you through a tutorial for building a social bookmarking application from the group using Django.

In this introduction, you will read about the following:

  • The MVC pattern in web development

  • Why we should use Python

  • Why we should use Django

  • The history of Django

 

MVC pattern in web development


Web development has made great progress during the last few years. It began as a tedious task that involved using a protocol called Common Gateway Interface (CGI) for interfacing external programs with the web server. The CGI applications used standard I/O facilities available to the C programming language in order to manually parse user input and produce page output. In addition to being difficult to work with, CGI required a separate copy of the program to be launched for each request. This used to quickly overwhelm servers.

Next, scripting languages were introduced to web development, and this inspired developers to create more efficient technologies. Languages such as Perl and PHP quickly made their way into the world of web development. As a result, common web tasks such as cookie handling, session management, and text processing became much easier. Although scripting languages included libraries to deal with day-to-day web-related tasks, they lacked unified frameworks, as libraries were usually disparate in design, usage, and conventions. Therefore, the need for cohesive frameworks arose.

A few years ago, the model-view-controller (MVC) pattern for web-based applications was introduced. This software engineering pattern separates data (model), user interface (view), and data-handling logic (controller) so that one can be changed without affecting the others. The benefits of this pattern are obvious. With it, designers can work on the interface without worrying about data storage or management. Developers are able to program the logic of data handling without getting into the details of presentation. As a result, the MVC pattern quickly found its way into web languages, and serious web developers started to embrace it in preference to previous techniques.

The following diagram illustrates how each of the components of the MVC pattern interacts with each other to serve a user request:

 

Why Python?


Python is a general purpose programming language. Although it is used for a wide variety of applications, Python is very suitable for developing web applications. It has a clean and elegant syntax. It is supported by a large library of standard and contributed modules, which covers everything from multi-threading to the zipping of files. The language's object-oriented model is especially suited for MVC style development.

Sooner or later, performance will become a major concern with web projects. Python's runtime environment shines here, as it is known to be fast and stable. Python supports a wide range of web servers through modules, including the famous Apache. Furthermore, it is available for all the major platforms: UNIX/Linux, Windows, and Mac. Python also supports a wide array of database servers, but you won't have to deal directly with them. Django provides a unified layer of access to all available database engines, as we will see later.

Python is a free software that you can download and freely use from http://python.org/. You are even allowed to distribute it without having to pay any fees. Access to the source code is available to those who want to add features or fix bugs. As a result, Python enjoys a large community of developers who quickly fix bugs and introduce new features.

Python is very easy to learn, and it is being adopted in many universities as the first programming language to be taught. Although this book assumes working knowledge of Python, advanced features will be explained as they are used. If you want to refresh your Python knowledge, you are recommended to read the official Python tutorial available at http://python.org/doc/ before continuing with this book.

To sum up, Python was chosen over many other scripting languages for this book. The reasons are:

  • A clean and elegant syntax

  • A large standard library of modules that covers a wide range of tasks

  • Extensive documentation

  • A mature runtime environment

  • Support for standard and proven technologies such as Linux and Apache

    Note

    If you want to learn more about Python and its features, these are two excellent sources: the official Python web site at http://python.org/ and the Python book Dive Into Python (freely available at http://www.diveintopython.org/).

 

Why Django?


Since the spread of the MVC pattern into web development, Python has provided quite a few choices when it comes to web frameworks such as Django, TurboGears, and Zope. Although choosing one out of many can be confusing initially, having several competing frameworks can only be a good thing for the Python community. That's because it drives the development of all the frameworks further and provides a rich set of options to choose from.

Django is one of the available frameworks for Python, so the question is: What sets it apart to become the topic of this book, and what makes it popular in the Python community? The next subsections will answer these questions by providing an overview of the main advantages of Django.

Tight integration between components

First of all, Django provides a set of tightly integrated components. All of these components have been developed by the Django team. Django was originally developed as an in-house framework for managing a series of news-oriented web sites. Later, its code was released on the Internet, and the Django team continued its development using the open source model. Because of its roots, Django's components were designed for integration, reusability, and speed from the start.

Object-Relational Mapper

Django's database component, the Object-Relational Mapper (ORM), provides a bridge between the data model and the database engine. It supports a large set of database systems, and switching from one engine to another is a matter of changing a configuration file. This gives the developer great flexibility if a decision is made to change from one database engine to another.

Clean URL design

The URL system in Django is very flexible and powerful. It lets you define patterns for the URLs in your application and define Python functions to handle each pattern. This enables developers to create URLs that are both user and search engine friendly.

Automatic administration interface

Django comes with an administration interface that is ready to be used. This interface makes the management of your application's data a breeze. It is also highly flexible and customizable.

Advanced development environment

In addition, Django provides a very nice development environment. It comes with a lightweight web server for development and testing. When the debugging mode is enabled, Django provides very thorough and detailed error messages with a lot of debugging information. All of this makes isolating and fixing bugs very easy.

Multilingual support

Django supports multilingual web sites through its built-in internationalization system. This can be very valuable for those working on web sites with more than one language. The system makes translating the interface a very simple task.

The standard features expected of a web framework are all available in Django. These include the following:

  • A template and text filtering engine with simple, but extensible syntax

  • A form generation and validation API

  • An extensible authentication system

  • A caching system for speeding up the performance of applications

  • A feed framework for generating RSS feeds

Even though Django does not provide a JavaScript library to simplify working with AJAX, choosing one and integrating it with Django is a straightforward matter, as we will see in later chapters.

So to conclude, Django provides a set of integrated and mature components with excellent documentation at http://www.djangoproject.com/documentation/, thanks to its large community of developers and users. With Django available, there has never been a better time to start learning a web development framework!

 

History of Django


Django started as an internal project at the Lawrence Journal-World newspaper in 2003. Often, the web development team there had to implement new features or even entire applications within hours. Therefore, Django was created to meet the fast deadlines of journalism web sites, while at the same time keeping the development process clean and maintainable. By the summer of 2005, Django became mature enough to handle several high-traffic sites, and the developers decided to release it to the public as an open source project. The project was named after the jazz guitarist, Django Reinhardt.

Now that Django is an open source project, it has gathered developers and users from all over the world. Bug fixes and new features are introduced on a daily basis, and the original development team keeps an eye on the whole process to make sure that Django remains what it is meant to be—a web framework for building clean, maintainable, and reusable web applications.

 

Summary


Web development has made large leaps of progress over the last few years. The advent of scripting languages, web frameworks, and AJAX made rapid development of web applications possible and easier than ever. This book takes you through a tutorial for building a Web 2.0 application using two hot technologies: Python and Django. The application allows users to store and share bookmarks. Many of the exciting Web 2.0 applications will be explained and developed throughout this book.

In the next chapter, we will set up our development environment by installing the necessary software, and get a feel for Django by creating our first application.

Django 1.0 Website Development
Unlock this book and the full library FREE for 7 days
Start now