Book Image

Django 1.0 Website Development

Book Image

Django 1.0 Website Development

Overview of 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.
Table of Contents (17 chapters)
Django 1.0 Web Site Development
Credits
About the author
About the reviewer
Preface

Preface

Django is a high-level Python web application framework designed to support the development of dynamic web sites, web applications, and web services. It is designed to promote rapid development and clean, pragmatic design. Therefore, it lets you build high-performing and elegant web applications quickly.

In this book you will learn about employing this MVC web framework, which is written in Python—a powerful and popular programming language. The book emphasizes utilizing Django and Python to create a Web 2.0 bookmark-sharing application, with many common features found in the Web 2.0 sites these days. The book follows a tutorial style to introduce concepts and explain solutions to problems. It is not meant to be a reference manual for Python or Django. Django will be explained as we build features throughout the chapters, until we realize our goal of having a working Web 2.0 application for storing and sharing bookmarks.

I sincerely hope that you will enjoy reading the book as much as I enjoyed writing it. And I am sure that by its end, you will appreciate the benefits of using Python and Django for your next project. Both Python and Django are powerful and simple, and provide a robust environment for rapid development of your dynamic web applications.

What this book covers

Chapter 1 gives you an introduction to MVC web development frameworks, and explains why Python and Django are the best tools to achieve the aim of this book.

Chapter 2 provides a step-by-step guide to installing Python, Django, and an appropriate database system so that you can create an empty project and set up the development server.

Chapter 3 creates the main page so that we have an initial view and a URL. You will learn how to create templates for both the main page and the user page. You will also write a basic set of data models to store your application's data..

Chapter 4 is where the application really starts to take shape, as user management is implemented. Learn how to log users in and out, create a registration form, and allow users to manage their own accounts by changing email or password details.

Chapter 5 explores how to manage your growing bank of content. Create tags, tag clouds, and a bookmark submission form, all of which interact with your database. Security features also come into play as you learn how to restrict access to certain pages and protect them against malicious input.

Chapter 6 enables you to enhance your application with AJAX and jQuery, since users can now edit entries in place and do live searching. Data entry is also made easier with the introduction of auto-completion.

Chapter 7 shows you how to enable users to vote and comment on their bookmark entries. You will also build a popular bookmarks page.

Chapter 8 focuses on the administration interface. You will learn how to create and customize the interface, which allows you to manage content and set permissions for users and groups.

Chapter 9 will give your application a much more professional feel through the implementation of RSS feeds and pagination.

Chapter 10 tackles social networks providing the "social" element of your application. Users will be able to build a friend network, browse the bookmarks of their friends, and invite their friends to join the web site.

Chapter 11 covers extending and deploying your application. You will also learn about advanced features, including offering the site in multiple languages, managing the site during high traffic, and configuring the site for a production environment.

Chapter 12 takes a brief look at the additional Django features that have not been covered elsewhere in the book. You will gain the knowledge required to further develop your application and build on the basic skills that you have learned throughout the book.

Who this book is for

This book is for web developers who want to learn how to build a complete site with Web 2.0 features, using the power of a proven and popular development system—Django—but do not necessarily want to learn how a complete framework functions in order to do this. Basic knowledge of Python development is required for this book, but no knowledge of Django is expected.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "We can include other contexts through the use of the include directive."

A block of code will be set as follows:

{% extends "base.html" %}
{% block title %}User Registration{% endblock %}
{% block head %}User Registration{% endblock %}
{% block content %}
<form method="post" action=".">
  {{ form.as_p }}
  <input type="submit" value="register" />
</form>
{% endblock %}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items will be shown in bold:

import os
from django.conf.urls.defaults import *
from bookmarks.views import *

site_media = os.path.join(
  os.path.dirname(__file__), 'site_media'
)

urlpatterns = patterns('',
  (r'^$', main_page),
  (r'^user/(\w+)/$', user_page),
  (r'^login/$', 'django.contrib.auth.views.login'),
  (r'^logout/$', logout_page),
  (r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
    {'document_root': site_media}),
)

Any command-line input or output is written as follows:

$ django-admin.py startproject django_bookmarks

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in our text like this: "clicking the Next button moves you to the next screen".

Tip

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply drop an email to , and mention the book title in the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or email .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code for the book

Visit http://www.packtpub.com/files/code/6781_Code.zip to directly download the example code.

The downloadable files contain instructions on how to use them.

Errata

Although we have taken every care to ensure the accuracy of our contents, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in text or code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration, and help us to improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata added to any list of existing errata. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.