The Django framework is relatively easy to learn and it solves many web-related questions such as project structure, database object-relational mapping, templating, form validation, sessions, authentication, security, cookies, internationalization, basic administration, creating interfaces to access data from scripts, and more. Django is based on the Python programming language, whose code is clear and easy to read. Django also has a lot of third-party modules that can be used in conjunction with your own apps. Django has an established and vibrant community where you can find source code, get help, and contribute.
Django Web Development Cookbook will guide you through all web development processes with the Django 1.6 framework. You will get started with the virtual environment and configuration of the project and then you will learn how to define a database structure with reusable components. After this, you will move on to exploring the forms and views used to enter and list data. Then, you will continue with responsive templates and JavaScript to create the best user experience. After that, you will find out how to tweak the administration to make the website editors happy. You will also learn how to integrate your own functionality into Django CMS. The next step will be learning how to use hierarchical structures. Then, you will find out that collecting data from different sources and providing data to others in different formats isn't as difficult as you thought. And finally, you'll be introduced to some programming and debugging tricks and will be shown how to deploy the project to a remote dedicated server.
In contrast to other Django books, this book will deal not only with the code of the framework itself, but also with some important third-party modules necessary for fully equipped web development. The book also gives examples of rich user interfaces using the Bootstrap frontend framework and the jQuery JavaScript library.
Chapter 1, Getting Started with Django 1.6, will guide you through the basic configuration that is necessary to start any Django project. It will cover topics such as the virtual environment, version control, and project settings.
Chapter 2, Database Structure, will teach you how to write reusable pieces of code to use in your models. When you create a new app, the first thing to do is to define your models. Also, you will be told how to manage database schema changes using South migrations.
Chapter 3, Forms and Views, will show you some patterns used to create the views and forms for your data.
Chapter 4, Templates and JavaScript, will show you practical examples of using templates and JavaScript together. We bring together templates and JavaScript because information is always presented to the user by rendered templates and in modern websites, JavaScript is a must for a richer user experience.
Chapter 5, Custom Template Filters and Tags, will show you how to create and use your own template filters and tags, as the default Django template system is quite extensive, and there are more things to add for different cases.
Chapter 6, Model Administration, will guide you through extending the default administration with your own functionality, as the Django framework comes with a handy prebuilt model administration.
Chapter 7, Django CMS, deals with the best practices of using Django CMS, which is the most popular open source content management system made with Django, and extending it for your needs.
Chapter 8, Hierarchical Structures, shows that whenever you need to create a tree-like structure in Django, the django-mptt module comes in handy. This chapter shows you how to use it and how to set administration for hierarchical structures.
Chapter 9, Data Import and Export, demonstrates to us that very often there are cases when we need to transfer data from and to different formats, and retrieve it from and provide it to different sources. This chapter deals with management commands for data import and also APIs for data export.
Chapter 10, Bells and Whistles, will show some additional snippets and tricks useful in web development, debugging, and deployment.
To develop with Django 1.6, you will need Python 2.6 or 2.7, the Pillow library for image manipulation, the MySQL database and MySQLdb bindings or PostgreSQL, virtualenv to keep each project's Python modules separated, and Git or Subversion for version control.
All other specific requirements are mentioned in each recipe separately.
If you have created websites with Django but you want to sharpen your knowledge and learn some good approaches for how to treat different aspects of web development, this book is for you. It is intended for intermediate and professional Django users who need to build projects that must be multilingual, functional on devices of different screen sizes, and which scale over time.
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, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "In the models.py
file of the guerrilla_patches
app, add the following content."
A block of code is set as follows:
# -*- coding: UTF-8 -*- from django.utils import text from slugify import slugify_de as awesome_slugify awesome_slugify.to_lower = True text.slugify = awesome_slugify
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
class ExtendedChangeList(main.ChangeList):
def get_translated_list(self, model, field_list):
language = get_language()
translated_list = []
opts = model._meta
Any command-line input or output is written as follows:
(myproject_env)$ fab dev deploy
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: "Go to Webmin | System | Scheduled Cron Jobs | Create a new scheduled cron job and create a scheduled cron job with these properties."
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 <[email protected]>
, 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.
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.
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.
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 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 <[email protected]>
with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
You can contact us at <[email protected]>
if you are having a problem with any aspect of the book, and we will do our best to address it.