Introduction

I read a lot of technical books about software and computer programming. This isn't because I have a great fondness for reading, nor do I actually like owning a massive collection of computer books that's slowly beginning to overtake every room in my home. I do it because at any given time, I'm usually working on a programming project and am faced with a dozen problems that I need to solve. These unsolved problems fester in my head. They scrape away at the surface of my brain like jagged rusty metal hooks. These books provide me sweet relief from these pains.

In my experience, there are two types of computer books: those that act as reference guides and those that act as tutorials. This book falls squarely in the latter category. While you need both tutorial and reference books in order to learn something, I tend to like tutorial books better, simply because they aid you in making better use of the reference books. For this reason, over the course of this book, we will be building one single Django project, to which we will add new features with each chapter and learn new parts of the Django web framework as we go.

There are lots and lots of Django apps floating around on the web. Many of these will contain perfectly good—and in some cases, absolutely spectacular—working code that you can use on your site. In other cases, the code is less than great, but still works. While I've taken a snippet of code from the open source community here and there throughout this book, I've mostly gone the do-it-myself route and implemented things from scratch. The reason for this is simple: when you're learning, rolling your own solutions at a lower level instead of just plugging in an app you found ready-made on Google Code or Django Snippets is much better for making the basic concepts stick to your brain. The drawback of this approach, of course, is that there are parts of the site we're going to develop in this book that are greatly simplified.

However, when you use snippets of code samples that are posted in various corners of the Internet by people all over world, you will still encounter problems. You'll get weird errors when you hook the new code into your site, and you'll end up having to read the Django docs and Django blogs and Django books to determine what's going wrong. My hope is that, after working through the examples in this book, you'll not only be much more adept at developing complex and powerful code with Django from scratch, you'll also have a much better grasp of dealing with these kinds of integration problems with existing third-party solutions when they arise. On top of this, you might also find yourself working to extend the functionality of an existing solution to suit your own needs, which is a good ability to have as well.

Who This Book Is For

This book is aimed at developers who are interested in learning more about the process of how to create a Django web site. Over the course of the book, we're going to create a single working e-commerce web site that we'll deploy into production at the very end. In each chapter, we'll tackle a particular feature or group of features that we want to add to the site, outline the requirements and discuss the related concepts, and then write code to implement each feature using Django. This will allow you to see how the different parts of a single Django project all fit together. In the end, you'll have a thorough grasp of how a Django web application is created, secured, optimized for search engines, tested, and finally deployed.

We're going to create a shopping cart site in this book, and while some of the sections cover problems that are specific to e-commerce web sites, most of the content has applications to other types of sites as well. For example, Chapter 8 covers implementation of internal site search so that customers can find things in our product catalog. Search functionality is a requirement of almost any data-driven web site. In Chapter 4, we create a shopping cart for our product catalog, allowing customers to aggregate products before they check out, and here you'll learn more about how you can use Django sessions in order to track information about your customers, whether or not they are logged in. The checkout functionality created in Chapter 5 covers the basics of Python network programming in order to integrate with third-party payment gateways, and the material covered is useful to anyone interested in integrating Django with web services.

This book does assume familiarity with the Python programming language. If you're a complete beginner and have never worked with Python, don't worry... it's a very simple language and you'll be able to catch on very quickly. If you're new to programming and would like an introduction, I'd suggest you take a look at Beginning Python: Second Edition, by Magnus Lie Hetland (Apress, 2008). If you're already familiar with at least one other programming language and just need to get caught up on the syntax of Python, I can heartily recommend you read Dive Into Python, by Mark Pilgram (Apress, 2004).

The Web Sites In This Book

In this book, I'm going to build a fictional e-commerce site that sells musical instruments and sheet music. The name of the site is "Modern Musician." Developers in the Django community have a penchant for naming their apps and projects after old-time musicians, like John Coltrane, Louis "Satchmo" Armstrong, and Duke Ellington. This tradition was started by the creators of the Django web framework, who chose to name it after guitarist Django Reinhardt, who is regarded by many as one of the greatest jazz guitarists of all time.

It didn't dawn on me until around the time I started writing Chapter 13 that the name "Modern Musician" might be construed as a tongue-in-cheek reference to this tradition in the Django community. In my defense, I originally created the Modern Musician e-commerce site in PHP, as a demo e-commerce site. Later, I implemented roughly the same Modern Musician site using Ruby on Rails, for the sole purpose of learning Rails. So when I got around to spawning this little project in Django, the last thing on my mind when naming the project was any attempt at ridicule. I did so out of tradition.

In the first 15 chapters of this book, we're going to build a single e-commerce web site. For those interested, the site we're going to create is available for public viewing at http://www.django-ecommerce.com/. While an administrative interface is part of the site that we're going to create in this book, the public site does not permit altering of data in the product catalog.

In Chapter 16, when we look at putting Django projects up on the Google App Engine, we're going to create a minimal shopping cart site, which is also available for public viewing at http://django-ecommerce.appspot.com/.

Source Code and Errata

We're going to write a lot of code in this book. It's not an overbearing amount, as Python is a very concise language and Django syntax tends to reduce the amount of repetitive code that you need to write. In spite of this, you still might find yourself wanting to have a copy of the code on hand so that you don't have to type in every last line. The source code for the site we're going to create in this book is available for download from the Apress web site.[1] (There's also a bunch of awesome books on there.)

If you happen to be reading a digital version of this book on your computer and have the option of selecting text, I'd be careful about copying code from your screen into your editor. Some characters might not transfer from electronic versions of this book into IDEs very well, as they might confuse the Python interpreter. You're much safer just typing it in yourself. You've been warned.

Lastly, while everyone has worked really hard to ensure that this book is grammatically and technically correct, some grammatical and technical "bugs" may have slipped in under our reviewing eyes. ("Bug" is a nice euphemism for "mistake," isn't it?) If you find an error and would like to politely rub it in my face, please feel free to submit it to this book's errata page on the Apress web site.[2]

If you'd like to contact me with any questions or concerns you have about the content of this book, shoot me an e-mail at: .



[1] http://www.apress.com/book/sourcecode

[2] http://www.apress.com/book/view/1430225351

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.41.142