0%

Book Description

From idea to prototype, a learner's guide for web development with the Django application framework

In Detail

Django, written in Python, is a web application framework designed to build complex web applications quickly without any hassle. It loosely follows the MVC pattern and adheres to the Don't Repeat Yourself principle, which makes a database-driven application efficient and highly scalable, and is by far the most popular and mature Python web framework.

This book is a manual that will help you build a simple yet effective Django web application. It starts by introducing Django, setting it up, and shows you how to code simple programs. You will then learn to build your first Twitter-like app. Later on, you will be introduced to Hashtags, AJAX to enhance the user interface, and tweets. You will then move on to create an administration interface, learn database connectivity, and use third-party libraries. Then you will learn to debug and deploy Django projects, and also get a glimpse of Django with AngularJS and Elasticsearch. By the end of the book, you will be able to leverage the Django framework to develop a fully functional web application with minimal effort.

What You Will Learn

  • Build Django web application right from scratch
  • Use version control to manage the development project
  • Learn to use Django with both SQL and NoSQL databases
  • Build faster and more efficient webpages using a frontend framework Twitter Bootstrap
  • Improve web application performance with caching
  • Enhance your user interface with AJAX and add flavors to your website
  • Deploy the Django web application to clouds such as AWS, Heroku, and OpenShift
  • Get familiar with AngularJS and Elasticsearch for Django

Downloading the example code for this book. 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.

Table of Contents

  1. Learning Django Web Development
    1. Table of Contents
    2. Learning Django Web Development
    3. Credits
    4. About the Authors
    5. About the Reviewers
    6. www.PacktPub.com
      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. Introduction to Django
      1. Why web development in the first place?
      2. What has changed in web development
      3. The MVC pattern in web development
        1. Multilingual support
      4. Why Django?
        1. Inside Django
          1. Django is mature
          2. Batteries included
          3. Tight integration between the component and modular framework
          4. Object-relational mapper
          5. Clean URL design
          6. Automatic administration interface
          7. Advanced development environment
          8. What's new in Django 1.6 and 1.7
      5. Supported databases
      6. What you will learn using this book
      7. Summary
    9. 2. Getting Started
      1. Installing the required software
        1. Installing Python
          1. Installing Python on Windows
          2. Installing Python on Unix/Linux
          3. Installing Python on Mac OS X
        2. Installing virtualenv
        3. Installing Django
          1. Django compatibility with operating systems – Windows versus Linux
          2. Installing Django on Windows
          3. Installing Django on Unix/Linux and Mac OS X
        4. Installing a database system
      2. Creating your first project
        1. Creating an empty project
        2. Setting up the database
        3. Launching the development server
      3. Summary
    10. 3. Code Style in Django
      1. Django coding style
        1. Understanding indentation in Python
          1. Doing indentation right – do we need four spaces per indentation level?
          2. The importance of blank lines
        2. Importing a package
          1. Grouping imported packages
        3. Naming conventions in Python/Django
      2. Using IDE for faster development
      3. Setting up your project with the Sublime text editor
      4. Setting up the PyCharm IDE
      5. The Django project structure
      6. Best practices – using version control
        1. Git – the latest and most popular version control tool
          1. How Git works
          2. Setting up your Git
          3. Branching in Git
      7. Setting up the database
      8. Launching the development server
      9. Faster web development
        1. Minimal Bootstrap
          1. The Django way
          2. Manual installation of Bootstrap
      10. Summary
    11. 4. Building an Application Like Twitter
      1. A word about Django terminology
      2. Setting up a basic template application
        1. Creating a virtual environment
      3. Installing Django
        1. Creating Django's template structure of the project
      4. Setting up the basic Twitter Bootstrap for the application
      5. URLs and views – creating the main page
      6. Introduction to class-based views
      7. Django settings for the mytweets project
      8. Putting it all together – generating user pages
        1. Familiarization with the Django models
        2. Relationships in models
          1. Many-to-one relationships
          2. One-to-one relationships
          3. Many-to-many relationships
      9. Models – designing an initial database schema
        1. Django's user objects
        2. Creating a URL
        3. Templates – creating a template for the Main Page
      10. Summary
    12. 5. Introducing Hashtags
      1. The hashtag data model
        1. Django forms
      2. Designing the tweet post form
      3. Creating a tag page
      4. Summary
    13. 6. Enhancing the User Interface with AJAX
      1. AJAX and its advantages
      2. Using an AJAX framework in Django
      3. Using the open source jQuery framework
        1. The jQuery JavaScript framework
          1. Element selectors
          2. jQuery methods
          3. Hiding and showing elements
          4. Accessing CSS properties and HTML attributes
          5. Manipulating HTML documents
          6. Traversing the document tree
          7. Handling events
          8. Sending AJAX requests
          9. What next?
      4. Implementing the searching of tweets
        1. Implementing a searching
      5. Implementing the live searching of tweets
      6. Editing a tweet in place without loading a separate page
        1. Implementing bookmark editing
        2. Implementing in-place editing of bookmarks
      7. Autocompletion of hashtags while submitting a tweet
      8. Summary
    14. 7. Following and Commenting
      1. Letting users follow another user
        1. The UserFollowers data model
        2. The user login model
        3. Adding or removing the follower
      2. Displaying the most followed user
      3. Summary
    15. 8. Creating an Administration Interface
      1. Customizing the administration interface
      2. Customizing listing pages
      3. Overriding administration templates
      4. Users, groups, and permissions
        1. User permissions
        2. Group permissions
        3. Using permissions in views
      5. Organizing content into pages – pagination
      6. Summary
    16. 9. Extending and Deploying
      1. Sending invitation e-mails to friends
        1. The invitation data model
        2. Handling activation links
      2. Internationalization (i18n) – offering the site in multiple languages
        1. Marking strings as translatable
        2. Creating translation files
        3. Enabling and configuring the i18n system
      3. Caching – improving the performance of your site during high traffic
        1. Enabling caching
        2. Configuring caching
          1. Caching the whole site
          2. Caching specific views
      4. Unit testing – automating the process of testing your application
        1. The test client
        2. Testing the registration view
      5. Deploying Django
        1. The production web server
      6. Summary
    17. 10. Extending Django
      1. Custom template tags and filters
      2. Class-based generic views
      3. Contributed sub-frameworks
      4. Flatpages
        1. Humanize
        2. Sitemap
        3. Cross-site request forgery protection
      5. The message system
      6. The subscription system
      7. User scores
      8. Summary
    18. 11. Database Connectivity
      1. SQL versus NoSQL
        1. SQL databases
          1. MySQL – open source
          2. PostgreSQL
        2. NoSQL databases
          1. MongoDB
          2. CouchDB
          3. Redis
      2. Setting up a database system
        1. Setting up MySQL
          1. Installing MySQL in Linux – Debian
          2. Installing the MySQL plugin for Python
        2. Migration and the need for migration
          1. The new features in Django migration
        3. Backend support
        4. How to do migrations?
          1. How migrations know what to migrate
        5. The migration file
        6. Django with NoSQL
      3. The single-page application project – URL shortener
        1. MongoEngine
          1. Connecting MongoDB with Django
          2. Authentication in Django
          3. Storing sessions
      4. Summary
    19. 12. Using Third-party Packages
      1. Diving into the world of open source
        1. What is an open source software?
        2. What's the difference between open source and other software?
      2. Using SocialAuth in Django projects
        1. How OAuth works
        2. Implementing social OAuth
        3. Creating a Twitter application
      3. Building REST APIs in Django
        1. Using Django Tastypie
          1. Implementing a simple JSON API
      4. Summary
    20. 13. The Art of Debugging
      1. Logging
      2. Debugging
        1. The Django debug toolbar
          1. Installing the Django debug toolbar
      3. IPDB – interactive way of busting bugs
      4. Summary
    21. 14. Deploying Django Projects
      1. The production web server
      2. The production database
      3. Turning off the debug mode
      4. Changing configuration variables
      5. Setting error pages
      6. Django on cloud
        1. EC2
        2. Google Compute Engine
        3. The open hybrid cloud application platform by Red Hat
        4. Heroku
        5. Google Application Engine
      7. Summary
    22. 15. What's Next?
      1. AngularJS meets Django
      2. Django search with Elasticsearch
        1. Installing an Elasticsearch server
          1. Communication between Elasticsearch and Django
            1. Creating an Elasticsearch index
            2. Feeding the index with data
            3. Retrieving search results from the index
      3. Summary
    23. Index
3.149.233.72