Book Image

Django Essentials

By : Samuel Dauzon
Book Image

Django Essentials

By: Samuel Dauzon

Overview of this book

<p>Django is a powerful Python web framework designed for rapid web application development. With the advent of frameworks such as Django, web developers have been forced to adopt MVC architectures and are encouraged to develop quality code. This quality allows several developers to work together easily and reduces the number of bugs due to human errors.</p> <p>Beginning with the basics of the Web and Django, the book explains the MVC pattern. It then moves on to explain the step-by-step installation of Python, PIP, and Django on Windows, Linux, and Mac OS. Furthermore, you will learn how to create templates, models, forms, and so on. After reading the book, you will be able to quickly create dynamic web applications with AJAX and an admin part.</p> <p>This book features a step-by-step approach that shows you how to program, create, and improve the quality of web applications using Django, with the help of Python.</p>
Table of Contents (20 chapters)
Django Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

For some years, web development has evolved through frameworks. Web development has become more efficient and has improved in quality. Django is a very sophisticated and popular framework. A framework is a set of tools designed to facilitate and standardize development. It allows the developer to benefit from very practical tools to minimize the development time. However, developing with frameworks requires knowledge about the framework and its proper usage. This book uses a step-by-step pedagogy to help novice developers learn how to easily deal with the Django framework. The examples in this book explain the development of a simple web tool: a text-based task manager.

What this book covers

Chapter 1, Django's Position on the Web, gives a short history of the Web and its evolution. It explains what a framework and MVC pattern are. It ends with a presentation of Django.

Chapter 2, Creating a Django Project, deals with the installation of the necessary software to use Django. At the end of this chapter, you will have a development environment that is ready to code.

Chapter 3, Hello World! with Django, describes Django routing after a reminder of regular expressions. It ends with an example of a simple controller that displays "Hello world!" on the user's browser.

Chapter 4, Working with Templates, explains how Django templates work. It covers the basics of the template language as well as the best practices for architecture templates and URL creation.

Chapter 5, Working with Models, describes the construction of models in Django. It also explains how to generate the database and how to maintain it with the South tool. This chapter also shows you how to set up the administration interface via the admin module.

Chapter 6, Getting a Model's Data with Querysets, explains how to perform queries on the database through models. Examples are used to test different types of queries.

Chapter 7, Working with Django Forms, discusses Django forms. It explains how to create forms with Django and how to treat them.

Chapter 8, Raising Your Productivity with CBV, focuses on a unique aspect of Django: class-based views. This chapter explains how to create CRUD interfaces in seconds.

Chapter 9, Using Sessions, explains how to use Django sessions. Different practical examples show the use of session variables and how to get the best out of them.

Chapter 10, The Authentication Module, explains how to use the Django authentication module. It covers registration, login, and access restriction to some pages.

Chapter 11, Using AJAX with Django, describes the basics of the jQuery library. Then, it shows a practical example of using AJAX with Django and explains the features of these pages.

Chapter 12, Production with Django, explains how to deploy a website with the Django web server such as Nginx and a PostgreSQL web system database.

Appendix, Cheatsheet, is a quick reference to the common methods or attributes useful to a Django developer.

What you need for this book

The software required for Django development are as follows:

  • Python 3

  • PIP 1.5

  • Django 1.6

Who this book is for

This book is for Python developers who want to learn how to create a website with a quality framework. The book is also for web developers who use other languages such as PHP and who wish to improve the quality and maintainability of their website. The book is for anyone who has Python basics and web basics as well as who wishes to work on one of the most advanced frameworks today.

Conventions

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

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the settings.py directive."

A block of code is set as follows:

from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'Work_msanager.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
)

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

root@debian: wget https://raw.github.com/pypa/pip/master/contrib
/get-pip.py
root@debian:python3 get-pip.py

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 the text like this: "Click on Advanced System Settings."

Note

Warnings or important notes appear in a box like this.

Note

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 send an e-mail to , and mention the book title via the subject of your message.

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

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the 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 improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. 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.