Django Essentials

Book description

Develop simple web applications with the powerful Django framework

In Detail

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.

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.

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.

What You Will Learn

  • Utilize the MVC pattern to create web applications
  • Use Django models to store information in the database and generate queries to access a database across models
  • Generate very maintainable forms with Django
  • Quickly develop web pages to create, read, update, and delete data from the model using class-based views
  • Construct users by using an authentication module to restrict access to certain pages
  • Use AJAX with Django
  • Install your website on Linux and access it through the Internet

Publisher resources

Download Example Code

Table of contents

  1. Getting Started with Django
    1. Table of Contents
    2. Getting Started with Django
    3. Credits
    4. About the Author
    5. About the Reviewers
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Django's Position on the Web
      1. From Web 1.0 to Web 2.0
        1. Web 1.0
        2. Web 2.0
      2. What is Django?
        1. Django – a web framework
      3. The MVC framework
      4. Why use Django?
      5. Summary
    9. 2. Creating a Django Project
      1. Installing Python 3
        1. Installing Python 3 for Windows
        2. Installing Python 3 for Linux
        3. Installing Python 3 for Mac OS
      2. Installing setuptools
        1. Installing setuptools for Windows
        2. Installing setuptools for Linux
        3. Installing setuptools for Mac OS
      3. Installing PIP
        1. Installing PIP for Windows
        2. Installing PIP for Linux
        3. Installing PIP for Mac OS
      4. Installing Django
        1. Installing Django for Windows
        2. Installing Django for Linux
        3. Installing Django for Mac OS
      5. Starting your project with Django
      6. Creating an application
      7. Configuring the application
      8. Summary
    10. 3. Hello World! with Django
      1. Routing in Django
      2. Regular expressions
        1. The uninterpreted characters
        2. The beginning and the end of the line
        3. The any character regular expression
        4. Character classes
        5. Validating the number of characters
      3. Creating our first URL
      4. Creating our first view
      5. Testing our application
      6. Summary
    11. 4. Working with Templates
      1. Displaying Hello world! in a template
      2. Injecting the data from the view to the template
      3. Creating dynamic templates
      4. Integrating variables in templates
        1. Conditional statements
        2. Looping in a template
      5. Using filters
        1. The upper and lower filters
          1. The lower filter
          2. The upper filter
        2. The capfirst filter
        3. The pluralize filter
        4. The escape and safe to avoid XSS filters
        5. The linebreaks filter
        6. The truncatechars filter
      6. Creating DRY URLs
      7. Extending the templates
      8. Using static files in templates
      9. Summary
    12. 5. Working with Models
      1. Databases and Django
      2. Migrations with South
        1. Installing South
        2. Using the South extension
      3. Creating simple models
        1. The UserProfile model
        2. The Project model
      4. The relationship between the models
        1. Creating the task model with relationships
      5. Extending models
      6. The admin module
        1. Installing the module
        2. Using the module
      7. Advanced usage of models
        1. Using two relationships for the same model
        2. Defining the str method
      8. Summary
    13. 6. Getting a Model's Data with Querysets
      1. The persisting model's data on the database
        1. Filling a model and saving it in the database
      2. Getting data from the database
        1. Getting multiple records
        2. Getting only one record
        3. Getting a model instance from the queryset instance
      3. Using the get parameter
      4. Saving the foreign key
      5. Updating records in the database
        1. Updating a model instance
        2. Updating multiple records
      6. Deleting a record
      7. Getting linked records
      8. Advanced usage of the queryset
        1. Using an OR operator in a queryset
        2. Using the lower and greater than lookups
        3. Performing an exclude query
        4. Making a raw SQL query
      9. Summary
    14. 7. Working with Django Forms
      1. Adding a developer without using Django forms
        1. Template of an HTML form
        2. The view using the POST data reception
      2. Adding a developer with Django forms
        1. CSRF protection
        2. The view with a Django form
        3. Template of a Django form
      3. The form based on a model
        1. The supervisor creation form
      4. Advanced usage of Django forms
        1. Extending the validation form
        2. Customizing the display of errors
        3. Using widgets
        4. Setting initial data in a form
          1. When instantiating the form
          2. When defining fields
      5. Summary
    15. 8. Raising Your Productivity with CBV
      1. The CreateView CBV
        1. An example of minimalist usage
      2. Working with ListView
        1. An example of minimalist usage
        2. Extending ListView
      3. The DetailView CBV
        1. An example of minimalist usage
        2. Extending DetailView
      4. The UpdateView CBV
        1. An example of minimalist usage
        2. Extending the UpdateView CBV
      5. The DeleteView CBV
      6. Going further by extending the CBV
        1. Using a custom class CBV update
      7. Summary
    16. 9. Using Sessions
      1. Creating and getting session variables
        1. An example – showing the last task consulted
      2. About session security
      3. Summary
    17. 10. The Authentication Module
      1. How to use the authentication module
        1. Configuring the Django application
        2. Editing the UserProfile model
      2. Adding a user
      3. Login and logout pages
      4. Restricting access to the connected members
        1. Restricting access to views
        2. Restricting access to URLs
      5. Summary
    18. 11. Using AJAX with Django
      1. Working with jQuery
      2. jQuery basics
        1. CSS selectors in jQuery
        2. Getting back the HTML content
        3. Setting HTML content in an element
        4. Looping elements
        5. Importing the jQuery library
      3. Working with AJAX in the task manager
      4. Summary
    19. 12. Production with Django
      1. Completing the development
      2. Selecting the physical server
      3. Selecting the server software
      4. Selecting the server database
      5. Deploying the Django website
        1. Installing PIP and Python 3
        2. Installing PostgreSQL
        3. Installing virtualenv and creating a virtual environment
      6. Installing Django, South, Gunicorn, and psycopg2
        1. Configuring PostgreSQL
        2. Adaptation of Work_manager to production
        3. Initial South migration
        4. Using Gunicorn
        5. Starting Nginx
      7. Summary
    20. A. Cheatsheet
      1. The field types in models
        1. The numerical field type
        2. The string field type
        3. The temporal field type
        4. Other types of fields
        5. Relationship between models
        6. The model meta attributes
        7. Options common to all fields of models
      2. The form fields
        1. Common options for the form fields
        2. The widget form
        3. Error messages (forms and models)
      3. The template language
        1. Template tags
          1. Loops in dictionaries
          2. Conditional statements
        2. The template filters
        3. The queryset methods
    21. Index

Product information

  • Title: Django Essentials
  • Author(s):
  • Release date: June 2014
  • Publisher(s): Packt Publishing
  • ISBN: 9781783983704